lkml.org 
[lkml]   [2010]   [Nov]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH] lib: vsprintf: fix invalid arg check
    On Wed, 10 Nov 2010, Andrew Morton wrote:

    > > "size" is size_t. If we want to check whether it was underflowed
    > > then we should cast it to ssize_t instead of int. When
    > > sizeof(size_t) > sizeof(int) the code sees UINT_MAX as underflow,
    > > but it is not.
    > >
    >
    > Does this patch fix any actual observed problem?
    >
    > > Compile tested.
    > >
    >
    > I guess not.
    >
    > > --- a/lib/vsprintf.c
    > > +++ b/lib/vsprintf.c
    > > @@ -1290,7 +1290,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
    > >
    > > /* Reject out-of-range values early. Large positive sizes are
    > > used for unknown buffer sizes. */
    >
    > Thousands of people would find that comment to be utterly mysterious.
    > I am one.
    >

    vsprintf() and sprintf() pass INT_MAX for an unbounded buffer length, so
    the cast to int here in the original code is correct. The type of
    interest is not of the passed size, but rather the return value of the
    function. The changelog is wrong: if sizeof(size_t) > sizeof(int) then
    the return value overflows.

    > > - if (WARN_ON_ONCE((int) size < 0))
    > > + if (WARN_ON_ONCE((ssize_t) size < 0))
    > > return 0;
    > >
    > > str = buf;


    \
     
     \ /
      Last update: 2010-11-10 22:41    [W:6.087 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site