This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [commit] printcmd.c, print_scalar_formatted, use strncpy.


Pedro Alves wrote:
On Wednesday 02 March 2011 23:00:23, Michael Snyder wrote:
strncpy2.txt
  2011-03-02  Michael Snyder  <msnyder@vmware.com>

* printcmd.c (print_scalar_formatted): Use strncpy for safety.

Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.192
diff -u -p -u -p -r1.192 printcmd.c
--- printcmd.c  26 Feb 2011 02:07:08 -0000      1.192
+++ printcmd.c  2 Mar 2011 22:55:38 -0000
@@ -533,7 +533,7 @@ print_scalar_formatted (const void *vala
            if (*cp == '\0')
              cp--;
          }
-       strcpy (buf, cp);
+       strncpy (buf, cp, sizeof (bits));
        fputs_filtered (buf, stream);
       }
       break;

We've been through this recently... This is not safe.



I'm slow today -- how is it not safe?


(note that sizeof (bits) is smaller than sizeof (buff)).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]