lkml.org 
[lkml]   [2014]   [Jun]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] staging: usbip: stub_main.c: Cleaning up missing null-terminate after strncpy call
From
Hi

True!
Sorry :-(

But then one would either operate strcpy outright.

Or use strlcpy then the code would be:

/* strlcpy() handles not include \0 */
len = strlcpy(busid, buf + 4, BUSID_SIZE);

/* busid needs to include \0 termination */
if (!(len < BUSID_SIZE))
return -EINVAL;


Or should we just let it be, perhaps?


Kind regards
Rickard Strandqvist


2014-06-10 8:57 GMT+02:00 Dan Carpenter <dan.carpenter@oracle.com>:
> On Wed, Jun 04, 2014 at 11:39:49PM +0200, Rickard Strandqvist wrote:
>> Added a guaranteed null-terminate after call to strncpy.
>>
>> This was partly found using a static code analysis program called cppcheck.
>>
>
> We already knew that the string was NUL terminated because we checked
> strnlen() on the lines before.
>
> regards,
> dan carpenter
>


\
 
 \ /
  Last update: 2014-06-10 23:41    [W:0.084 / U:0.372 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site