From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id 876443857715; Thu, 25 May 2023 17:10:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 876443857715 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685034601; bh=vV2upCcWqSzlgP4ox1/p9oc3mXKiJNWyXYqGbydaVR8=; h=From:To:Subject:Date:From; b=oAaMhoNGo4Ex8ehuI3hB7GH19UejiVCJ4WUGBDeNpFtleY4GrrHAC/EUiHZiUUhfM 5teigLNdwbjA2Y/NWNd/eEV9hlRqTOXd7t58V6KdMmmOumuo+PLyjMxZOlvzuF4a5M +wuo87gCk9updBiq7FpEGIAxwGHZOpCpOXaz07k4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc] elf: fix handling of negative numbers in dl-printf X-Act-Checkin: glibc X-Git-Author: Roy Eldar X-Git-Refname: refs/heads/master X-Git-Oldrev: 44d4d3bdcff67c7fa0b0c046fef9919e9c66c1b2 X-Git-Newrev: dae801527386f94e9d2fabf23c37863d1b599153 Message-Id: <20230525171001.876443857715@sourceware.org> Date: Thu, 25 May 2023 17:10:01 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dae801527386f94e9d2fabf23c37863d1b599153 commit dae801527386f94e9d2fabf23c37863d1b599153 Author: Roy Eldar Date: Thu May 25 17:41:58 2023 +0300 elf: fix handling of negative numbers in dl-printf _dl_debug_vdprintf is a bare-bones printf implementation; currently printing a signed integer (using "%d" format specifier) behaves incorrectly when the number is negative, as it just prints the corresponding unsigned integer, preceeded by a minus sign. For example, _dl_printf("%d", -1) would print '-4294967295'. Signed-off-by: Roy Eldar Reviewed-by: Florian Weimer Diff: --- elf/dl-printf.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/elf/dl-printf.c b/elf/dl-printf.c index e8b9900370..6efb4c019a 100644 --- a/elf/dl-printf.c +++ b/elf/dl-printf.c @@ -1,5 +1,6 @@ /* printf implementation for the dynamic loader. Copyright (C) 1997-2023 Free Software Foundation, Inc. + Copyright The GNU Toolchain Authors. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -150,19 +151,25 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg) if (long_mod) { if ((long int) num < 0) - negative = true; + { + num = -num; + negative = true; + } } else { if ((int) num < 0) { - num = (unsigned int) num; + num = -(unsigned int) num; negative = true; } } #else if ((int) num < 0) - negative = true; + { + num = -num; + negative = true; + } #endif }