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

Michael Snyder msnyder@vmware.com
Wed Mar 2 23:56:00 GMT 2011


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)).



More information about the Gdb-patches mailing list