On Tue 2019-02-19 13:06:17, Andy Shevchenko wrote: > On Tue, Feb 19, 2019 at 5:07 AM Sergey Senozhatsky > <sergey.senozhatsky.w...@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 > > > > forcing sprintf() to write "(invalid address)" to a 16-bytes buffer, > > but the thing is - strlen("(invalid address)") > 16.
Good catch! > It would print as many characters as buffer allows. In your case above > the use of sprintf() is a bit fragile. Heh, I do not see it used anywhere in the code. Only "%pi6" is used in a real code and always a safe way. > But yes, the error messages should not be longer than 8 / 16 bytes > depending on 32- or 64-bit build we have. Well, better be on the safe side. I'll move it at the beginning of the patchset. Best Regards, Petr PS: I am a bit busy with some other things. I'll send v7 later. I think that it is a material for 5.2. This patchset would deserve some testing in linux-next and we are already too close to the 5.1 merge window.