GNU bug report logs - #7347
[PATCH] stat: do not rely on undefined behavior in printf formats

Previous Next

Package: coreutils;

Reported by: Paul Eggert <eggert <at> cs.ucla.edu>

Date: Sat, 6 Nov 2010 21:00:03 UTC

Severity: normal

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jim Meyering <jim <at> meyering.net>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 7347 <at> debbugs.gnu.org
Subject: bug#7347: [PATCH] stat: do not rely on undefined behavior in printf formats
Date: Sat, 06 Nov 2010 22:53:31 +0100
Paul Eggert wrote:
> I have not pushed this, as I understand you're trying to put out a
> release, but this fixes some portability bugs in 'stat', such that it
> was relying on undefined behavior, which presumably could cause
> 'stat' to dump core, or worse, on non-GNU platforms.
>
> The downside of this patch is that the "I" printf flag is now ignored.
> However, support for "I" wasn't working anyway (because of time stamp
> fractions), so this isn't much of a loss.  We can add proper "I"
> support later, if there's demand for it.
>
> Subject: [PATCH] stat: do not rely on undefined behavior in printf formats
>
> * src/stat.c (digits, printf_flags): New static vars.
> (make_format): New function.
> (out_string, out_int, out_uint, out_uint_o, out_uint_x):
> (out_minus_zero): Use it to avoid undefined behavior when invoking
> printf.
> (print_it): Check for invalid conversion specifications such as
> %..X and %1-X, which would otherwise rely on undefined behavior
> when invoking printf.
> * tests/misc/stat-nanoseconds: Check that the "I" printf flag
> doesn't mess up in the C locale, as it formerly did on non-GNU
> hosts.

Thanks for the patch!
I looked through it, applied it and tested it.
I see fixes (admittedly fringe, as you say, but still)
and don't see anything that might cause trouble, so go ahead and push it.
Nobody will miss the "I" flag.  I think I've never even seen it used.




This bug report was last modified 14 years and 201 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.