aboutsummaryrefslogtreecommitdiff
path: root/elf
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2022-10-11 14:22:35 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2022-10-28 11:16:09 +0100
commiteef17d4d9fcd38c5cbb9bc9515ba72d1773b67a2 (patch)
treeb7b53fe307a94d583aa7681a7b0d7653c45a3e02 /elf
parent68619ddb3b7e8b64a6b849e4972e67163f7659c3 (diff)
downloadglibc-eef17d4d9fcd38c5cbb9bc9515ba72d1773b67a2.zip
glibc-eef17d4d9fcd38c5cbb9bc9515ba72d1773b67a2.tar.gz
glibc-eef17d4d9fcd38c5cbb9bc9515ba72d1773b67a2.tar.bz2
elf: Fix alloca size in _dl_debug_vdprintf
The alloca size did not consider the optional width parameter for padding which could cause buffer underflow. The width is currently used e.g. by _dl_map_object_from_fd which passes 2 * sizeof(void *) which can be larger than the alloca buffer size on targets where sizeof(void *) >= 2 * sizeof(unsigned long). Even if large width is not used on existing targets it is better to fix the formatting code to avoid surprises. Reviewed-by: Florian Weimer <fweimer@redhat.com>
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-printf.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/elf/dl-printf.c b/elf/dl-printf.c
index 429d2e8..00c1140 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. */