From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 48F423858D1E for ; Thu, 8 Sep 2022 10:15:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 48F423858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662632158; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4SDtHSGM4SrRPIT1KXRufoFEJNL62iB+6TLeret930I=; b=LlFfUcGMHYtL9chwtrHF3mjNfpUnk7uUYd6eY9rTGOClqKqD8FSXEdLzUhA9jKRHnXIOs0 BUKVBhW/datQ7Nibu24fdW1rYDCBU4BXouFY2Am4nX0wJCCWhafIbeL/s1ErwUvOSJ7nzQ p+RzwbU07zIUb/NyLRSv7tOf5WqxtLA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-237-BYDykpD5ORWgol9p7h6r3A-1; Thu, 08 Sep 2022 06:15:57 -0400 X-MC-Unique: BYDykpD5ORWgol9p7h6r3A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78DF41818800; Thu, 8 Sep 2022 10:15:57 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 604F22026D4C; Thu, 8 Sep 2022 10:15:56 +0000 (UTC) From: Florian Weimer To: Javier Pello Cc: libc-alpha@sourceware.org Subject: Re: [PATCH 1/4] elf: Fix hwcaps string size overestimation References: <20220905200652.d69204581d15c64647da5cd2@otheo.eu> <20220905200901.07ccae81662ec00d68094f7e@otheo.eu> Date: Thu, 08 Sep 2022 12:15:54 +0200 In-Reply-To: <20220905200901.07ccae81662ec00d68094f7e@otheo.eu> (Javier Pello's message of "Mon, 5 Sep 2022 20:09:01 +0200") Message-ID: <874jxi8945.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,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: * Javier Pello: > 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) This patch looks good to me. I will push it for you after some testing. Thanks, Florian