From patchwork Fri Sep 29 13:52:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 76885 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 05E20387541E for ; Fri, 29 Sep 2023 13:52:42 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 49B743861904 for ; Fri, 29 Sep 2023 13:52:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49B743861904 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=1695995548; 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: content-transfer-encoding:content-transfer-encoding; bh=nBZuMBry1kYA14mFq7qr/wXtKxzH94etvfgTVjrbjf8=; b=gxpv6sn1McLZacy7hGJH4tJARg0WRGxSvMuwUX9t2+O8Jw56jKfVb6I8cJt/cX1LyBxdp0 tWCAAJAtejORJjb3kng5Eq5Qa1tAAcCVL3wepK9PYmytzl3kZ3omxMimIclYnpiCyLWg2c L5oujJgSV11XVXrBTOuMvnqDWd7vi4U= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-GfTiIeJJOMWUypx5vs5auw-1; Fri, 29 Sep 2023 09:52:26 -0400 X-MC-Unique: GfTiIeJJOMWUypx5vs5auw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6557c921deeso222741926d6.2 for ; Fri, 29 Sep 2023 06:52:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695995545; x=1696600345; 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=nBZuMBry1kYA14mFq7qr/wXtKxzH94etvfgTVjrbjf8=; b=cMuC7n524iAYnT07ZkCmL7DIwIHg87atr2NXVHnULV7RRwl1E8WWychLkjkkbgATKD n6vSOoJhrUTwvkKWEhEMh0mT5OezpyHmkpVGzGJK4LRCdGT1P8QYaQ+ApUX9OMyWRWT5 5LpoXK6ZBrBF+uzr8y1aX2eg/NzQMqx3dVmz6uAy4EZ2wg+JwfIds/lSURScL4tSmlD4 odJrEDTOjjmMOMwvigaHSIE4Qxcnehs5y2drNROBla8X39lps87Lh1LLPNdQ0WqSRmoc evbi07VHpkcvIBFO3ionwX4EBwTRhcPPvGceiEiD8Fw0ajp2M6pQDfKfa7mkFqJ1xUEC nQwQ== X-Gm-Message-State: AOJu0YyFpxp62pDvw+4Lo0qU9y7tD5rgvPAF39ElGg1mOZVoscdQQYam gAmTYlaYtu2XpkY6CuC6kpwEP6NAuxZerVLABxhN85saaUa4tBhJEaTkSBkTbVoqPl7wY0OZw3u ZS9nhNNqTQ1fFMcCFR5NEGAY9xmhzULDRYq1TfWhxf7DdrboXC7BcjZMm4AlwiKQocmn6jYwGnQ +52lMI X-Received: by 2002:a0c:a984:0:b0:65b:86b:e008 with SMTP id a4-20020a0ca984000000b0065b086be008mr3598027qvb.16.1695995545010; Fri, 29 Sep 2023 06:52:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7goSeJBEhS6o2i4zQ6YrCyPViHfzKK75vzNgsGMDzKUCQMyfcUb9DZbG5Csr+lpaNa8q72Q== X-Received: by 2002:a0c:a984:0:b0:65b:86b:e008 with SMTP id a4-20020a0ca984000000b0065b086be008mr3598004qvb.16.1695995544614; Fri, 29 Sep 2023 06:52:24 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id r26-20020a05620a03da00b00775838e79f8sm1059815qkm.134.2023.09.29.06.52.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 06:52:24 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH] elf: Get rid of alloca usage in _dl_start_profile Date: Fri, 29 Sep 2023 09:52:19 -0400 Message-ID: <20230929135222.1195747-1-josimmon@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org Replace alloca usage with a scratch_buffer. --- elf/dl-profile.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/elf/dl-profile.c b/elf/dl-profile.c index 8be0065fbd..8ae50020bb 100644 --- a/elf/dl-profile.c +++ b/elf/dl-profile.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -201,6 +202,8 @@ _dl_start_profile (void) int s_scale; #define SCALE_1_TO_1 0x10000L const char *errstr = NULL; + struct scratch_buffer sbuf; + scratch_buffer_init (&sbuf); /* Compute the size of the sections which contain program code. */ for (ph = GL(dl_profile_map)->l_phdr; @@ -318,8 +321,14 @@ _dl_start_profile (void) /* First determine the output name. We write in the directory OUTPUT_DIR and the name is composed from the shared objects soname (or the file name) and the ending ".profile". */ - filename = (char *) alloca (strlen (GLRO(dl_profile_output)) + 1 - + strlen (GLRO(dl_profile)) + sizeof ".profile"); + size_t filename_len = (strlen (GLRO(dl_profile_output)) + 1 + + strlen (GLRO(dl_profile)) + sizeof ".profile"); + if (!scratch_buffer_set_array_size (&sbuf, 1, filename_len)) + { + _dl_error_printf ("failed to allocate memory"); + return; + } + filename = sbuf.data; cp = __stpcpy (filename, GLRO(dl_profile_output)); *cp++ = '/'; __stpcpy (__stpcpy (cp, GLRO(dl_profile)), ".profile"); @@ -339,6 +348,7 @@ _dl_start_profile (void) __close_nocancel (fd); _dl_error_printf (errstr, filename, __strerror_r (errnum, buf, sizeof buf)); + scratch_buffer_free (&sbuf); return; } @@ -380,6 +390,7 @@ _dl_start_profile (void) _dl_error_printf ("%s: file is no correct profile data file for `%s'\n", filename, GLRO(dl_profile)); + scratch_buffer_free (&sbuf); return; } @@ -483,6 +494,8 @@ _dl_start_profile (void) /* Turn on profiling. */ running = 1; + + scratch_buffer_free (&sbuf); }