[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-devel
Subject:    Re: [PATCH 4/6] winealsa.drv: Append hw address to handle to prevent
From:       Vitaliy Margolen <wine-devel () kievinfo ! com>
Date:       2010-08-30 4:09:48
Message-ID: 4C7B2F0C.6090405 () kievinfo ! com
[Download RAW message or body]

On 08/29/2010 12:43 AM, Jeff Cook wrote:
> On Tue, Aug 3, 2010 at 7:49 AM, Vitaliy Margolen
> <wine-devel@kievinfo.com>  wrote:
>>> +    memcpy(ww->ds_desc.szDesc, description,
>>> +            min( (sizeof(ww->ds_desc.szDesc) - 1), strlen(description))
>>> );
>>
>> This does not guarantee that ww->ds_desc.szDesc will be \0 terminated.
>>
>> Vitaliy.
>>
> What do you want me to do? This looks pretty safe to me and I just
> copied the block from elsewhere and replaced the variables. Do you
> want me to manually read to the end of ww->ds_desc.szDesc and replace
> with a \0? Sorry for the noobness.

strlen returns number of characters without terminating \0. If you using 
memcpy to copy strings you must add additional byte (if destination is big 
enough). Or explicitly zero terminate the destination string (if result was 
truncated).

What you really want is a strlcpy() which unfortunately not present on all 
platforms. And don't even think using strncpy - it's the worst string 
function ever made.

Just the fact that you copied the exact code doesn't automatically make it 
correct.

Vitaliy.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic