From: Joe Simmons-Talbott <josimmon@redhat.com>
To: libc-alpha@sourceware.org
Cc: Joe Simmons-Talbott <josimmon@redhat.com>
Subject: [PATCH] elf: Get rid of alloca usage in _dl_start_profile
Date: Fri, 29 Sep 2023 09:52:19 -0400 [thread overview]
Message-ID: <20230929135222.1195747-1-josimmon@redhat.com> (raw)
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 <fcntl.h>
#include <inttypes.h>
#include <limits.h>
+#include <scratch_buffer.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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);
}
--
2.39.2
next reply other threads:[~2023-09-29 13:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 13:52 Joe Simmons-Talbott [this message]
2023-10-03 19:33 ` Joe Simmons-Talbott
2023-10-10 19:05 ` Joe Simmons-Talbott
2023-10-30 12:24 ` Joe Simmons-Talbott
2023-10-30 12:44 ` Andreas Schwab
2023-10-31 20:17 ` Joe Simmons-Talbott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230929135222.1195747-1-josimmon@redhat.com \
--to=josimmon@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).