From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id A49D83858D32 for ; Thu, 25 May 2023 14:42:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A49D83858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f60804faf4so5335275e9.3 for ; Thu, 25 May 2023 07:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685025755; x=1687617755; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=exex9pO7VkooC8NNbehmeaahrDB+Ac3bvvFFshU80HM=; b=B6SHjXQYjjE11wqs36C/7GG+eVVyaMzA7zDyaubnaL/Dnu8OaERqjmXYEBy7rvD7A2 4UIggICMak/tt3ApWXqRQmpH9rNimPIIw0ZxmHhvY22Gn6P3okcA7d9bvzZIL46V6mfr tEBJqB8/YJZ31+Y/dyxuUQrzYuj2C25BeQ+j2a9vSZXywDdpursZ3MHz/pqUPdYA1ngC D8oai5+JV7YnvS9Nao/h+yPT4yZRF0Tnhxwo9sF4Ug/rseqZivgRAGHlt/nkg9+XOD2l axhOD7veeTk4QWcwKJEbDEhif30yb6iUutDseRUPCbAXGVOVJLf50X9q2qE/oe/ofz7N V5cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685025755; x=1687617755; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=exex9pO7VkooC8NNbehmeaahrDB+Ac3bvvFFshU80HM=; b=Alm3dMSl93i4WuDQmrixa+y2ugkUjdLlqruAwEi+/U2xvaDKrGVbYh6W6pu3PmVYyF N4N2Xf/uxK4knGzPrc1Bnba8zyB9Qm8odNfbXfdLT5s1Sj1vXV7S2KtuWHw3tuFBVA4M KLLlpI/vFUftfznC9MRitTOPhgnjj5xrtLru9RcbIUyFhtBQFROA6wnU5Wf1snegxtKP J2GI5/iQNmDjiSbU2BKQWQi0xcvWEU4xr//VkOisanwCQOBmEU63arzXyA6UMuLOJAoH vHJtcYTxKKuUxPRduoN9Ofpct+zfU1g8fDK1NZKFUmPw7XOR3DtVFiA58T4ohsRYBikb 1n/A== X-Gm-Message-State: AC+VfDyZITU9NpRVwyzDkSevGupx6RiDTFLHPpGpXM2pPOYQAC0RCdim NsTK5471b/7gOvT+7vV4T/g= X-Google-Smtp-Source: ACHHUZ7g7DbrQdUx6DL+Ulns0Hop7x9imVOXsky8wQHzDXip1SoBhB8yCf77DZa3OvCuHCKsIS4lAQ== X-Received: by 2002:a1c:e901:0:b0:3f4:2973:b8d0 with SMTP id q1-20020a1ce901000000b003f42973b8d0mr2735022wmc.2.1685025755131; Thu, 25 May 2023 07:42:35 -0700 (PDT) Received: from DESKTOP-FOQ07IR.localdomain ([2a00:a041:e93f:fc3f:c8bb:8ad7:8b86:a3a]) by smtp.gmail.com with ESMTPSA id 2-20020a05600c028200b003f42cc3262asm5873447wmk.34.2023.05.25.07.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:42:34 -0700 (PDT) From: Roy Eldar To: fweimer@redhat.com Cc: Roy Eldar , libc-alpha@sourceware.org, carlos@redhat.com Subject: [PATCH v2] elf: fix handling of negative numbers in dl-printf Date: Thu, 25 May 2023 17:41:58 +0300 Message-Id: <20230525144159.2935-1-royeldar0@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <87fs7kq2ey.fsf@oldenburg.str.redhat.com> References: <87fs7kq2ey.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: _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 --- 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 } -- 2.30.2