mailing list of musl libc
 help / color / mirror / code / Atom feed
From: enh <enh@google.com>
To: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] [RFC] trap on invalid printf formats
Date: Wed, 21 Jun 2023 15:10:26 -0700	[thread overview]
Message-ID: <CAJgzZoqQv5=mCLTqs5EP7314f9bVH_vzLQ-6toh2-RmMs=RcJQ@mail.gmail.com> (raw)
In-Reply-To: <20230621213746.GM4163@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 1358 bytes --]

i really should do this in bionic... currently we only abort on %n (which
is explicitly _not_ supported) or %w with a silly size.

for random junk, we currently do what the BSDs do (since that's where this
code originally came from):

      default: /* "%?" prints ?, unless ? is NUL */
        if (ch == '\0') goto done;
        /* pretend it was %c with argument ch */
        cp = buf;
        *cp = ch;
        size = 1;
        sign = '\0';
        break;

from running a quick test program, macOS and glibc seem to work similarly,
which increases the chances that there's incorrect code out there. (clang
does at least warn "warning: invalid conversion specifier '?'
[-Wformat-invalid-specifier]" by default, though. gcc doesn't.)

On Wed, Jun 21, 2023 at 2:38 PM Rich Felker <dalias@libc.org> wrote:

> Inspired by a new instance of some bitrotted software using %Lu
> instead of %llu, attached is a draft patch to catch such errors rather
> than silently leaving missing output.
>
> I don't know if this is a good idea to actually do (note: probably
> matching changes should be made in wide printf and maybe also scanf if
> so) but I'm posting it here in case anyone wants to experiment or
> discuss. Note that there is no conformance distinction since invalid
> format strings are undefined behavior.
>
> Rich
>

[-- Attachment #2: Type: text/html, Size: 1828 bytes --]

  reply	other threads:[~2023-06-21 22:10 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 [this message]
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

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='CAJgzZoqQv5=mCLTqs5EP7314f9bVH_vzLQ-6toh2-RmMs=RcJQ@mail.gmail.com' \
    --to=enh@google.com \
    --cc=musl@lists.openwall.com \
    /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).