lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <28c9af6b1ddf4664bbfed973e2f01874@AcuMS.aculab.com>
Date: Fri, 16 Feb 2024 09:58:21 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Stephen Hemminger' <stephen@...workplumber.org>, Hangbin Liu
	<liuhangbin@...il.com>
CC: "netdev@...r.kernel.org" <netdev@...r.kernel.org>, "jhs@...atatu.com"
	<jhs@...atatu.com>
Subject: RE: [PATCH iproute2] tc: u32: check return value from snprintf

From: Stephen Hemminger <stephen@...workplumber.org>
> Sent: 12 February 2024 16:54
> 
> On Mon, 12 Feb 2024 15:24:49 +0800
> Hangbin Liu <liuhangbin@...il.com> wrote:
> 
> > On Sat, Feb 10, 2024 at 05:04:23PM -0800, Stephen Hemminger wrote:
> > > Add assertion to check for case of snprintf failing (bad format?)
> > > or buffer getting full.
> > >
> > > Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
> >
> > Hi Stephen,
> >
> > Is there a bug report or something else that we only do the assertion
> > for tc/f_u32.c?
> >
> > Thanks
> > Hangbin
> 
> No bug, it is not possible to trigger with current code.
> Return of < 0 only happens with improper format string,
> and the overrun would only happen if buffer was not big enough
> The bsize is SPRINT_BUF() which is 64 bytes.
> 
> It is more a way to avoid some code checker complaining in future.

What are you testing?
If you are testing snprintf() then maybe a check for <0 is sane.
But otherwise it is a waste of time.

FWIW do you know what (any) printf() function should return for (eg):
	int len = MAXINT;
	len = snprintf(NULL, 0, "%*s %*s", len, "abcd", len, "1234");

My brain doesn't think that a 'bad format' generates -1.
You can get -1 from fprintf() (if a write() fails) which largely
means that code looking at the result of fprintf() is broken.
(You need to do fflush() and ferror() if you want to know
if a write failed, and you can't reliably assume it is the
length.)

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ