mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: "Alex Xu (Hello71)" <alex_y_xu@yahoo.ca>
Cc: musl@lists.openwall.com, Markus Wichmann <nullplan@gmx.net>
Subject: Re: [musl] [PATCH] [RFC] trap on invalid printf formats
Date: Thu, 22 Jun 2023 19:51:53 -0400	[thread overview]
Message-ID: <20230622235152.GO4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <1687470871.bzv5u1iuij.none@localhost>

On Thu, Jun 22, 2023 at 07:37:22PM -0400, Alex Xu (Hello71) wrote:
> Excerpts from Rich Felker's message of June 22, 2023 10:45 am:
> > FWIW I don't think there are a lot of these cases left in the wild at
> > all, but I'm not sure. it might be nice to do some distro-wide testing
> > with this patch applied (which is what I had in mind posting it) and
> > see if any problems are caught before really considering whether to
> > pursue upstreaming it.
> 
> Unfortunately, it seems fairly widespread:
> https://codesearch.debian.net/search?q=printf.*%5B%25%5DL%5Bud%5D+-package%3Agcc+-package%3Allvm*+path%3A.*%5C.c%24&literal=0
> 
> The most painful example:
> 
> #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__APPLE_CC__) || defined(__APPLE__) || defined(ARGUS_SOLARIS)
>     sprintf (pbuf, "%llu", value);
> #else
>     sprintf (pbuf, "%Lu", value);
> #endif
> 
> (copied and pasted 17 times in the same file, of course)

Which file are you looking at? Some of the results I see are Linux
(the kernel) using its own very-nonstandard printf format specifier
system. Those aren't relevant at all.

All of the rest are bugs where the software is silently malfunctioning
now. Some of these are junk code like examples/* etc. but presumably a
lot are actual bugs that need to be fixed, where something is
malfunctioning now.

> I did some research and the most likely source of %Lu is the Linux 
> man-pages, which, before 1999 or thereabouts, said:
> 
> > • The optional character l (ell) specifying that a following d, i, o, 
> > u, x, or X conversion applies to a pointer to a long int or unsigned 
> > long int argument, or that a following n conversion corresponds to a 
> > pointer to a long int argument.  Linux provides a non ANSI compliant 
> > use of two l flags as a synonym to q or L.  Thus ll can be used in 
> > combination with float conversions.  *This usage is, however, strongly 
> > discouraged.*
> >
> > • The character L specifying that a following e, E, f, g, or G 
> > conversion corresponds to a long double argument, or a following d, i, 
> > o, u, x, or X conversion corresponds to a long long argument.  Note 
> > that long long is not specified in ANSI C and therefore not portable 
> > to all architectures.
> 
> Emphasis added. So, pre-C99, L was in fact the recommended modifier for 
> long long.

As I read it, the usage that was discouraged was using ll as an alias
for L with float conversions. Not use of ll where it was the right
form.

In any case, I'm not sure what we can take away from the history. ll
was the form that ended up getting standardized (probably because it
didn't "steal" any additional letter that might be used for other
things on existing implementations or in the future), and both q and
the overloading of L got rejected.

Rich

      reply	other threads:[~2023-06-22 23:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 21:37 Rich Felker
2023-06-21 22:10 ` enh
2023-06-22 14:35 ` Markus Wichmann
2023-06-22 14:45   ` Rich Felker
2023-06-22 23:37     ` Alex Xu (Hello71)
2023-06-22 23:51       ` Rich Felker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230622235152.GO4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=alex_y_xu@yahoo.ca \
    --cc=musl@lists.openwall.com \
    --cc=nullplan@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).