mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: [musl] [PATCH] [RFC] trap on invalid printf formats
Date: Wed, 21 Jun 2023 17:37:49 -0400	[thread overview]
Message-ID: <20230621213746.GM4163@brightrain.aerifal.cx> (raw)

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

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: printf-trap.diff --]
[-- Type: text/plain, Size: 486 bytes --]

diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index 33019ff1..c3bd4d31 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -10,6 +10,7 @@
 #include <inttypes.h>
 #include <math.h>
 #include <float.h>
+#include "atomic.h"
 
 /* Some useful macros */
 
@@ -652,8 +653,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
 	return 1;
 
 inval:
-	errno = EINVAL;
-	return -1;
+	a_crash();
 overflow:
 	errno = EOVERFLOW;
 	return -1;

             reply	other threads:[~2023-06-21 21:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 21:37 Rich Felker [this message]
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

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=20230621213746.GM4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --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).