public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Szabolcs Nagy <nsz@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/arm/morello/main] elf: Fix alloca size in _dl_debug_vdprintf
Date: Wed, 23 Nov 2022 14:39:26 +0000 (GMT)	[thread overview]
Message-ID: <20221123143926.1AB2B3853573@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=eee747d8cce17473ae3312ce6818253d4222c251

commit eee747d8cce17473ae3312ce6818253d4222c251
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
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.  */

             reply	other threads:[~2022-11-23 14:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 14:39 Szabolcs Nagy [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-10-27 13:49 Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221123143926.1AB2B3853573@sourceware.org \
    --to=nsz@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).