From patchwork Mon Dec 30 16:31:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 854252 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp6521675wrq; Mon, 30 Dec 2024 08:32:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVRorrr8O9x+kxz2D7J6A1UDlw+DTmLoaOKdZSzr+hr18Jd/SvJe3crfKpcNYs+KD5qpwGtzQ==@linaro.org X-Google-Smtp-Source: AGHT+IGu4Jtuxv5J3Wxlf5npZx8qN+MAPjvyzkOXvYtrft5Ggk+EonSQ3wLdvSaWjKewtr29DsGv X-Received: by 2002:a05:6214:2b84:b0:6d8:a1fe:729e with SMTP id 6a1803df08f44-6dd233af2b4mr574612586d6.46.1735576340165; Mon, 30 Dec 2024 08:32:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1735576340; cv=pass; d=google.com; s=arc-20240605; b=HcGp0J8ObTts5uc+OvVj3ZYAhqwoVarxiPWM6u0+2XyQc17uEg2Q/DyBnOKL6T4dDd 3aRjXnEkbEQHupP8iwoGK1H5+UmZ7AolueMAJgdemMoSKJgPrSObHCY+elLJrJjJCN3i b3Wc/t2mDAybPQZYhP/2A7llfJEFr7VyitKrxJZdeXe2Sz5gP4KjEHnR3MtLEXiMNAkN iIGfx+zGen9UstY0wQUDiHF4JpimH7nCDqGp84KAF43i0/EZl9p3aMm5g+o0WD2e7Yp/ YlOl05kwlfdtDkDCf6vj0XnLf5Qxxg/GXO0aT8w2OxOIad82ZbAXetCf+2Kz2MeWs7UK GHvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter:arc-filter:dmarc-filter:delivered-to:dkim-filter; bh=iOFRo45+aIi7JMZDM93F2ZJQZaP06uePKEzTT+ORtRM=; fh=xV8Gp349bHw1ljD2lFQRwhGaJ4bIEzpeFyS/N97S3Sw=; b=JQ1pcunhXL2THlGXOBMJr2yxliW8P05yqylb3qlQMnJy7rnyrBbIYBaX4dKptx5bQF nPVzCLrYF8XBbDM85VQIhNVlZCHZSVlruQh/E6UJeyccKf7cBwY/zQDsve1PZ/Aty5ui oF9XaBd1+xvPKdLGRyDCHeiCjmn1FYfTt7HwstUqENU/akq08XNdK+Zb0HFExBw6yQuH xTgmPFIhFZlQCVGT9Ybfu/EWItcQLuUUPieQTVT0oNHUSJJf4IDl8B45iPeVeJrZejOT rUsj3uO5kQr0ODeZdVEOpwCZpZaymT/vxniZMtT5kMEQEUZ5qUSsCvuGyKJXU6vNL8xp WB1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HTY8sI5E; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 71dfb90a1353d-51b68d79f88si7720384e0c.179.2024.12.30.08.32.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2024 08:32:20 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HTY8sI5E; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A66DB3858C32 for ; Mon, 30 Dec 2024 16:32:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A66DB3858C32 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=HTY8sI5E X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 335F03858D1E for ; Mon, 30 Dec 2024 16:32:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 335F03858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 335F03858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735576321; cv=none; b=JFAEgNxWhXBL3fJ2a3w3d00PpFXVJdyGwwXXU1CAJype9ZWCNEtmN2/gmitzGx2iQYyU//ZiJOBEelzq+WI640wirIjmZVuSjt7tVI5DODt/xkX5XaqKnp9cvdG7GpwrraVHM5rh/ljuKGAKTNOlF3Jv8BS7ZA5Yqk3EWsbxCAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735576321; c=relaxed/simple; bh=G9RSt7lEPj1aYO2ywxXdDRfdcAuOtUjKRhgfSlbhxDk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Sx/qd4rI1yr+wMDxRdjX3Jx2yuNvtpgshryELA8rEhbsjGVctmZ8RlUHSFM6xoGg8vdH5SroyZzR6OaNYBH7b7RhpuMFF1PXrSOSSauA0bAPTnqjMhfIc5orQFt1b/UZqMpANvWalzA/Ch3oxfSGKPUOpsFJwal+ZIye7wNH+S4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 335F03858D1E Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2165448243fso146089175ad.1 for ; Mon, 30 Dec 2024 08:32:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735576320; x=1736181120; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=iOFRo45+aIi7JMZDM93F2ZJQZaP06uePKEzTT+ORtRM=; b=HTY8sI5El3EQRGY3wRhLbC2i9EgJ6L0F4H2MfyhImhQlNXJCzbX3gq6W2QTQMVpnso ZFYM11DhI/wRb7pNsV4nwR8hfBYbjEwZDUzCvZM67kKTREdKnedqUOjAhnJ5ylshWwlM K72acGPgHTLhNR0iU/kBk5tIplIne16WZ1piX5OGlxinzjdDU6D6QErbjsNUwzxxXJxl lnQAdvcX5oJB/o5s9nRqVYd4uvTjC7JcfG8rAOsn4JuvwsabRotBpHBDnff2UwTSQrLN Aa9rG6SG2szutqgosBaLhC4plCUqduPr0pv96HpaaKg/5etTFbvWV9TXTpNBBetzqMsz 44Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735576320; x=1736181120; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iOFRo45+aIi7JMZDM93F2ZJQZaP06uePKEzTT+ORtRM=; b=D4YWEAWcAaxESrGjCRSJf++5N70lpHsqs+7a0Wr6wftT6Y8i7b426jN4DBZ+hI7ksu 84iZBcT73huv2yjpeMkmjfkRskPFfQn7PeeMU5BRXyEI88YGsNGb4J1nBMdSn11sC2OJ eiWgVsKpQO4cSGYENTQbdx0sNZvEBloMvGjvv9ttxW/4X0ppFgLB3BVZBCi5O6/PZ34z mQD6bsD0628HuHyWKhwXb9nqkkj+RkRebvzigLFWTxZMWpX6ec1uZ2gMs+fq00SFvvln 37pJUY/JxsuqKy4OW50cWOd73QDEIKGWEpY3QCfNENpBhSXhj0mtQcQVEFCVp3H01O4B NInQ== X-Gm-Message-State: AOJu0YyGvV7CDcRfvDMlFySBG5LIoUPYiRs5wlq8UOmfljc2JqLhDdne nZGaYMS8O/Qw/i8p9yoXvGWFjzj5RzgTdEgehM15f2cOuxlI37gf3YXyOKBYFHTa0tjFagdivpN 4 X-Gm-Gg: ASbGncvVE3C1Q4DDGomoCvIXqhoJzEUnSf78DcGETM3oMeNNr72rIJSMR21/E2dCv8M BEJ6iVeXGOpKWJxJqf8j6DBdxtiqJHJ4w3QUesVgLW02r2A+C/YmN+5+uPu8+UGo70go3XsozrF W1qYi5fB5NMys9I/UwvygKbTSKNrinL+gqlCTZL6mtfNtj4QqXY//T5uek0Cr3RYZOMK4S8ddjP BaG+izyG190VqM2g+OPeReVMMbhQnxm13KxwjKpqIzLvCh5CQwrVljhw2i8D2H4G3cd3Vjhagts QX2KbHmKpJ4ktjJDyAOXPqw8qtUv X-Received: by 2002:a05:6a00:35ce:b0:725:eb85:f7ef with SMTP id d2e1a72fcca58-72abddcaf2fmr51186520b3a.14.1735576320023; Mon, 30 Dec 2024 08:32:00 -0800 (PST) Received: from ubuntu-vm.. (201-92-184-234.dsl.telesp.net.br. [201.92.184.234]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8162ddsm19437741b3a.17.2024.12.30.08.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2024 08:31:59 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer , Adhemerval Zanella Subject: [PATCH] assert: Remove the use of %n from __assert_fail_base (BZ #32456) Date: Mon, 30 Dec 2024 13:31:44 -0300 Message-ID: <20241230163153.2399453-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org The require size for mmap can be inferred from __vasprintf return value. It also fixes tst-assert-2 when building with --enable-fortify, where even if the format is not translated, __readonly_area fails because malloc can not be used. Checked on aarch64-linux-gnu. --- assert/assert-perr.c | 2 +- assert/assert.c | 27 ++++++++++----------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/assert/assert-perr.c b/assert/assert-perr.c index 0010cbc278..8a03620b4c 100644 --- a/assert/assert-perr.c +++ b/assert/assert-perr.c @@ -32,7 +32,7 @@ __assert_perror_fail (int errnum, char errbuf[1024]; char *e = __strerror_r (errnum, errbuf, sizeof errbuf); - __assert_fail_base (_("%s%s%s:%u: %s%sUnexpected error: %s.\n%n"), + __assert_fail_base (_("%s%s%s:%u: %s%sUnexpected error: %s.\n"), e, file, line, function); } libc_hidden_def (__assert_perror_fail) diff --git a/assert/assert.c b/assert/assert.c index 3a16f85394..3834ddd864 100644 --- a/assert/assert.c +++ b/assert/assert.c @@ -15,24 +15,17 @@ License along with the GNU C Library; if not, see . */ -#include -#include +#include #include #include -#include -#include -#include -#include -#include +#include #include #include -#include +#include extern const char *__progname; -#include -#include #define fflush(s) _IO_fflush (s) /* This function, when passed a string containing an asserted @@ -56,12 +49,12 @@ __assert_fail_base (const char *fmt, const char *assertion, const char *file, FATAL_PREPARE; #endif - int total; - if (__asprintf (&str, fmt, - __progname, __progname[0] ? ": " : "", - file, line, - function ? function : "", function ? ": " : "", - assertion, &total) >= 0) + int total = __asprintf (&str, fmt, + __progname, __progname[0] ? ": " : "", + file, line, + function ? function : "", function ? ": " : "", + assertion); + if (total >= 0) { /* Print the message. */ (void) __fxprintf (NULL, "%s", str); @@ -129,6 +122,6 @@ void __assert_fail (const char *assertion, const char *file, unsigned int line, const char *function) { - __assert_fail_base (_("%s%s%s:%u: %s%sAssertion `%s' failed.\n%n"), + __assert_fail_base (_("%s%s%s:%u: %s%sAssertion `%s' failed.\n"), assertion, file, line, function); }