From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id A44B33851523; Thu, 27 Oct 2022 13:49:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A44B33851523 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666878565; bh=mQ8LMFUCuqxena8w/vddIxeUAfGM4/Hhiw/2lqFFd9g=; h=From:To:Subject:Date:From; b=aBfWLQuj1WPFWakNZ7CTpAgu/KWJ7xWZbF3X1HgDZTfU74gto5Q9/DzvkAfkSV5Dz o+RwTNCcerfYkTs0QtDY+e/ESCXCslqWiInbC2rX3PjOE0fMD2mjrvuVuKwgeb1ZQr L+/GkWrV5rtspDIPOCg+eiOiJwiUNl31B4oVEQU4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] elf: Fix alloca size in _dl_debug_vdprintf X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: 01359abab8f5b7f44e6aa4260eb5f3f878d7ff4a X-Git-Newrev: 4197d863dee1894831759bc8c4543f0f05d26fd9 Message-Id: <20221027134925.A44B33851523@sourceware.org> Date: Thu, 27 Oct 2022 13:49:25 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4197d863dee1894831759bc8c4543f0f05d26fd9 commit 4197d863dee1894831759bc8c4543f0f05d26fd9 Author: Szabolcs Nagy Date: Tue Oct 11 14:22:35 2022 +0100 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. 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. */