From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chen Gang Subject: Re: [PATCH] cifs: extend the buffer length enought for sprintf() using Date: Sun, 06 Oct 2013 08:49:41 +0800 Message-ID: <5250B3A5.9020901@asianux.com> References: <51E5E9DA.8020603@asianux.com> <20130717072431.5d8a22b3@tlielax.poochiereds.net> <51E73F1E.4010804@asianux.com> <20130717212559.71b7af06@corrin.poochiereds.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Shirish Pargaonkar , Steve French , linux-cifs , samba-technical , Richard Weinberger , Joe Perches , Al Viro , Thomas Gleixner To: Jeff Layton Return-path: In-Reply-To: <20130717212559.71b7af06-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org> Sender: linux-cifs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: 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