lkml.org 
[lkml]   [2014]   [Apr]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] staging: line6: fix possible overrun
On Sat, Apr 26, 2014 at 07:09:22PM +0200, Laurent Navet wrote:
> The strcpy operation may write past the end of the fixed-size destination
> buffer if the source buffer is too large.
>
> Found by coverity scan : CID 144979
>
> Signed-off-by: Laurent Navet <laurent.navet@gmail.com>
> ---
> build tested only
>
> drivers/staging/line6/audio.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/line6/audio.c b/drivers/staging/line6/audio.c
> index 171d80c..65f5cd4 100644
> --- a/drivers/staging/line6/audio.c
> +++ b/drivers/staging/line6/audio.c
> @@ -32,9 +32,10 @@ int line6_init_audio(struct usb_line6 *line6)
>
> line6->card = card;
>
> - strcpy(card->id, line6->properties->id);
> + strncpy(card->id, line6->properties->id, (sizeof(card->id)-1));
> strcpy(card->driver, DRIVER_NAME);
> - strcpy(card->shortname, line6->properties->name);
> + strncpy(card->shortname, line6->properties->name,
> + (sizeof(card->shortname)-1));
> /* longname is 80 chars - see asound.h */
> sprintf(card->longname, "Line6 %s at USB %s", line6->properties->name,
> dev_name(line6->ifcdev));

Would not it be better to return -EINVAL (or some other error) instead?

Now you will possibly truncate the name.

--
Mateusz Guzik


\
 
 \ /
  Last update: 2014-04-26 23:01    [W:0.096 / U:0.592 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site