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

David Collier-Brown davec-b at rogers.com
Thu Jul 18 18:40:37 MDT 2013

On 07/17/2013 09:25 PM, Jeff Layton wrote:
> On Thu, 18 Jul 2013 09:04:30 +0800
> Chen Gang <gang.chen at asianux.com> wrote:
>> 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).
This is a valid argument if one knows that for all time, the length is
unchanging (:-))
As we've seen it was previously wrong, some caution may be in order.

Perhaps  "if (snprintf(...) >= MAX_USERNAME_SIZE) { complain_loudly() }"


David Collier-Brown,         | Always do right. This will gratify
System Programmer and Author | some people and astonish the rest
davecb at spamcop.net           |                      -- Mark Twain
(416) 223-8968

More information about the samba-technical mailing list