mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] [RFC] trap on invalid printf formats
@ 2023-06-21 21:37 Rich Felker
  2023-06-21 22:10 ` enh
  2023-06-22 14:35 ` Markus Wichmann
  0 siblings, 2 replies; 6+ messages in thread
From: Rich Felker @ 2023-06-21 21:37 UTC (permalink / raw)
  To: musl

[-- 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;

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-22 23:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-21 21:37 [musl] [PATCH] [RFC] trap on invalid printf formats 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

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).