[PATCH] cifs: extend the buffer length enought for sprintf() using

Chen Gang gang.chen at asianux.com
Sat Oct 5 18:49:41 MDT 2013


On 07/18/2013 09:25 AM, Jeff Layton wrote:
>> > > Maybe it would be good to go ahead and turn that sprintf() into a
>> > > snprintf() too?
>> > > 
>> 
>> Hmm... sprintf() declares to code readers, in current condition, we want
>> to print all source information without any truncation.
>> 
>> So if we know the source max length precisely, we'd better to allocate
>> the related buffer to print them all instead of use snprintf().
>> 
>> If we do not know the source max length precisely or we have to limit
>> the destination length, we need use snprintf() to fit with destination
>> max length (declare to the code readers, the source information may be
>> truncated).
>> 
>> 

My original idea for snprintf() is incorrect, the reason is: "Of course
you would have to check the return value of snprintf() to detect a
truncation and  abort..." (Thank Richard).



Thanks.
-- 
Chen Gang


More information about the samba-technical mailing list