From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id 78782388551B; Thu, 15 Sep 2022 13:44:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78782388551B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663249445; bh=YA/IIEvbTN9yuE6y+ff49H00xTHK9un16Xk1Ca1UyIY=; h=From:To:Subject:Date:From; b=i8878BGwToOysNTMdftpK2tkW40sRZoI3tifzTd3hQXCzhkvqzNIj09F8j4Yd9DIv uxAEbBjHVGEQvXeIgNOLYFRwT3NopqNIbJgIeZfJSYaFOiRD3e42be46rSoDm9Awbl tbobA/7DbERni491rQ8njKwFA65codmNTIGqgjFQ= 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/release/2.35/master] elf: Fix hwcaps string size overestimation X-Act-Checkin: glibc X-Git-Author: Javier Pello X-Git-Refname: refs/heads/release/2.35/master X-Git-Oldrev: 55a636430bd382fb9537e6d33cc6bc57bc2660c1 X-Git-Newrev: f4687bb41689ffcebc8744bed754a960045de733 Message-Id: <20220915134405.78782388551B@sourceware.org> Date: Thu, 15 Sep 2022 13:44:05 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f4687bb41689ffcebc8744bed754a960045de733 commit f4687bb41689ffcebc8744bed754a960045de733 Author: Javier Pello Date: Mon Sep 5 20:09:01 2022 +0200 elf: Fix hwcaps string size overestimation 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 (cherry picked from commit a23820f6052a740246fdc7dcd9c43ce8eed0c45a) Diff: --- 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 6f161f6ad5..92eb53790e 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)