public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] elf: Fix _dl_debug_vdprintf stack buffer underflow
@ 2022-10-12 14:15 Szabolcs Nagy
0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2022-10-12 14:15 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=059dd1983c8ee1a01c556e3dbe412791f43c2b8a
commit 059dd1983c8ee1a01c556e3dbe412791f43c2b8a
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue Oct 11 14:22:35 2022 +0100
elf: Fix _dl_debug_vdprintf stack buffer underflow
When printing numbers the alloca buffer size did not consider the
optional width parameter for padding. The width is used e.g. by
_dl_map_object_from_fd which passes '(int) sizeof (void *) * 2'
which can be larger than the buffer size on systems where
sizeof (void *) >= 2 * sizeof (unsigned long). But even if large
width is not used currently it is better to handle it to avoid
surprises.
Diff:
---
elf/dl-printf.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/elf/dl-printf.c b/elf/dl-printf.c
index d3264ba96c..10efa925bd 100644
--- a/elf/dl-printf.c
+++ b/elf/dl-printf.c
@@ -163,8 +163,11 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
/* We use alloca() to allocate the buffer with the most
pessimistic guess for the size. Using alloca() allows
having more than one integer formatting in a call. */
- char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int));
- char *endp = &buf[1 + 3 * sizeof (unsigned long int)];
+ int size = 1 + 3 * sizeof (unsigned long int);
+ if (width + 1 > size)
+ size = width + 1;
+ char *buf = (char *) alloca (size);
+ char *endp = &buf[size];
char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0);
/* Pad to the width the user specified. */
^ permalink raw reply [flat|nested] 2+ messages in thread
* [glibc/arm/morello/main] elf: Fix _dl_debug_vdprintf stack buffer underflow
@ 2022-10-26 15:10 Szabolcs Nagy
0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2022-10-26 15:10 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=11a22680b7409018f85c11119c477c063625b405
commit 11a22680b7409018f85c11119c477c063625b405
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue Oct 11 14:22:35 2022 +0100
elf: Fix _dl_debug_vdprintf stack buffer underflow
When printing numbers the alloca buffer size did not consider the
optional width parameter for padding. The width is used e.g. by
_dl_map_object_from_fd which passes '(int) sizeof (void *) * 2'
which can be larger than the buffer size on systems where
sizeof (void *) >= 2 * sizeof (unsigned long). But even if large
width is not used currently it is better to handle it to avoid
surprises.
Diff:
---
elf/dl-printf.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/elf/dl-printf.c b/elf/dl-printf.c
index d3264ba96c..10efa925bd 100644
--- a/elf/dl-printf.c
+++ b/elf/dl-printf.c
@@ -163,8 +163,11 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
/* We use alloca() to allocate the buffer with the most
pessimistic guess for the size. Using alloca() allows
having more than one integer formatting in a call. */
- char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int));
- char *endp = &buf[1 + 3 * sizeof (unsigned long int)];
+ int size = 1 + 3 * sizeof (unsigned long int);
+ if (width + 1 > size)
+ size = width + 1;
+ char *buf = (char *) alloca (size);
+ char *endp = &buf[size];
char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0);
/* Pad to the width the user specified. */
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-26 15:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 14:15 [glibc/arm/morello/main] elf: Fix _dl_debug_vdprintf stack buffer underflow Szabolcs Nagy
2022-10-26 15:10 Szabolcs Nagy
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 read-only IMAP folder(s) and NNTP newsgroup(s).