From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by sourceware.org (Postfix) with ESMTPS id 50D893857016 for ; Mon, 5 Sep 2022 18:10:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 50D893857016 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=otheo.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=otheo.eu Received: (Authenticated sender: #01#@otheo.eu) by mail.gandi.net (Postfix) with ESMTPSA id AA09640009 for ; Mon, 5 Sep 2022 18:10:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=otheo.eu; s=gm1; t=1662401414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MrTF08RoRlq85AEj+HLZscda8RLyM7fLWloCVN00KnI=; b=F5uiu0Jk79fjUdPg10Hoop5Fj1Fb948A1mbQGqmxUNMGeapuI5+K/UMO3Vm32cG31ANvWG fUf2SWgxFgJwWxfq48FqEJqcKDDFm//O8FZvm8VdatpeaJVOeUD1CsPLDyAJlL+usLu72h r52WgLL48IrXXIytJ20GBcptD7bI+fBGvpkbjNr/r99eEtxi5TAx8XygIA4k+amFrMFor8 ZbPrs4CJvvDR3EG9SdjP1LWYy8MyfbnEcTe2QjxqVSDOD3m6eTfx4fb/I1RSoRcZ9TxInG I9qyJyp2Gc7FZ6jUUEMqKVOSIoffj0RjDK0tZILKjp0AxZCIpab86TS7FTEdsg== Date: Mon, 5 Sep 2022 20:09:01 +0200 From: Javier Pello To: libc-alpha@sourceware.org Subject: [PATCH 1/4] elf: Fix hwcaps string size overestimation Message-Id: <20220905200901.07ccae81662ec00d68094f7e@otheo.eu> In-Reply-To: <20220905200652.d69204581d15c64647da5cd2@otheo.eu> References: <20220905200652.d69204581d15c64647da5cd2@otheo.eu> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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: Commit dad90d528259b669342757c37dedefa8577e2636 added glibc-hwcaps support for LD_LIBRARY_PATH and, for this, it adjusted the total string size required in _dl_important_hwcaps. However, in doing so it inadvertently altered the calculation of the size required for the power set strings, as the computation of the power set string size depended on the first value assigned to the total variable, which is later shifted, resulting in overallocation of string space. Fix this now by using a different variable to hold the string size required for glibc-hwcaps. Signed-off-by: Javier Pello --- elf/dl-hwcaps.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c index 6f161f6a..92eb5379 100644 --- a/elf/dl-hwcaps.c +++ b/elf/dl-hwcaps.c @@ -193,7 +193,7 @@ _dl_important_hwcaps (const char *glibc_hwcaps_prepend, /* Each hwcaps subdirectory has a GLIBC_HWCAPS_PREFIX string prefix and a "/" suffix once stored in the result. */ hwcaps_counts.maximum_length += strlen (GLIBC_HWCAPS_PREFIX) + 1; - size_t total = (hwcaps_counts.count * (strlen (GLIBC_HWCAPS_PREFIX) + 1) + size_t hwcaps_sz = (hwcaps_counts.count * (strlen (GLIBC_HWCAPS_PREFIX) + 1) + hwcaps_counts.total_length); /* Count the number of bits set in the masked value. */ @@ -229,11 +229,12 @@ _dl_important_hwcaps (const char *glibc_hwcaps_prepend, assert (m == cnt); /* Determine the total size of all strings together. */ + size_t total; if (cnt == 1) - total += temp[0].len + 1; + total = temp[0].len + 1; else { - total += temp[0].len + temp[cnt - 1].len + 2; + total = temp[0].len + temp[cnt - 1].len + 2; if (cnt > 2) { total <<= 1; @@ -255,6 +256,7 @@ _dl_important_hwcaps (const char *glibc_hwcaps_prepend, /* This is the overall result, including both glibc-hwcaps subdirectories and the legacy hwcaps subdirectories using the power set construction. */ + total += hwcaps_sz; struct r_strlenpair *overall_result = malloc (*sz * sizeof (*result) + total); if (overall_result == NULL) -- 2.36.0