lkml.org 
[lkml]   [2019]   [Feb]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v6 9/9] vsprintf: Avoid confusion between invalid address and value
On Tue, Feb 19, 2019 at 5:07 AM Sergey Senozhatsky
<sergey.senozhatsky.work@gmail.com> wrote:

> Suppose, in my driver I want to sprintf() IPv4 address. The longest
> possible address is 3 * 4 (%d%d%d) + 3 bytes (dots) + terminating NULL.
> E.g. 111.111.111.111
>
> So I can allocate a 16-bytes buffer (stack or slab) and accidentally
> do an %piS sprintf() on a corrupted in_addr struct:
>
> char buf[16];
> sprintf(buf, "%piS", in_addr);
>
> forcing sprintf() to write "(invalid address)" to a 16-bytes buffer,
> but the thing is - strlen("(invalid address)") > 16.

It would print as many characters as buffer allows. In your case above
the use of sprintf() is a bit fragile.

But yes, the error messages should not be longer than 8 / 16 bytes
depending on 32- or 64-bit build we have.

--
With Best Regards,
Andy Shevchenko

\
 
 \ /
  Last update: 2019-02-19 12:06    [W:0.092 / U:21.264 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site