[PATCH] stdio: Check the first character is a digit before calling read_int

panzhe0328 panzhe@kylinos.cn
Thu Aug 7 08:05:53 GMT 2025


The read_int function does not check if the first character is a digit.
Therefore, it is necessary to perform this check before calling read_int.

Signed-off-by: panzhe0328 <panzhe@kylinos.cn>
---
 stdio-common/vfprintf-internal.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c
index fa41e1b242..62e478a058 100644
--- a/stdio-common/vfprintf-internal.c
+++ b/stdio-common/vfprintf-internal.c
@@ -794,6 +794,13 @@ Xprintf_buffer (struct Xprintf_buffer *buf, const CHAR_T *format,
 
       /* Given width in format string.  */
     LABEL (width):
+      if (!ISDIGIT (*f))
+        {
+          __set_errno (EINVAL);
+	  Xprintf_buffer_mark_failed (buf);
+          goto all_done;
+        }
+
       width = read_int (&f);
 
       if (__glibc_unlikely (width == -1))
-- 
2.25.1



More information about the Libc-alpha mailing list