[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <24d45f0868b74a3ba4924f031e968c55@AcuMS.aculab.com>
Date: Fri, 28 Aug 2020 07:39:25 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Kees Cook' <keescook@...omium.org>,
Denis Efremov <efremov@...ux.com>
CC: Julia Lawall <julia.lawall@...ia.fr>,
Joe Perches <joe@...ches.com>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"linux-usb@...r.kernel.org" <linux-usb@...r.kernel.org>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
cocci <cocci@...teme.lip6.fr>,
"accessrunner-general@...ts.sourceforge.net"
<accessrunner-general@...ts.sourceforge.net>,
Alex Dewar <alex.dewar90@...il.com>
Subject: RE: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs
From: Kees Cook
> Sent: 27 August 2020 23:21
...
>
> Agreed. This just makes me cringe. If the API design declares that when
> a show() callback starts, buf has been allocated with PAGE_SIZE bytes,
> then that's how the logic should proceed, and it should be using
> scnprintf...
>
> show(...) {
> size_t remaining = PAGE_SIZE;
>
> ...
> remaining -= scnprintf(buf, remaining, "fmt", var args ...);
> remaining -= scnprintf(buf, remaining, "fmt", var args ...);
> remaining -= scnprintf(buf, remaining, "fmt", var args ...);
Not quite what you had in mind, maybe:
char *end = buf + PAGE_SIZE;
buf += scnprintf(buf, end - buf, ...);
return PAGE_SIZE - (end - buf);
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists