public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] elf: Remove glibc.rtld.enable_secure check from parse_tunables_string
@ 2024-05-07 17:04 Adhemerval Zanella
0 siblings, 0 replies; only message in thread
From: Adhemerval Zanella @ 2024-05-07 17:04 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c8a0e21da63b6e5c7f558cdd31a5d208c1677df3
commit c8a0e21da63b6e5c7f558cdd31a5d208c1677df3
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon May 6 13:18:46 2024 -0300
elf: Remove glibc.rtld.enable_secure check from parse_tunables_string
And move it to parse_tunables. It avoids a string comparison for
each tunable.
Checked on aarch64-linux-gnu and x86_64-linux-gnu.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Diff:
---
elf/dl-tunables.c | 58 ++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 38 insertions(+), 20 deletions(-)
diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index 1db80e0f92..63cf8c7ab5 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -119,6 +119,17 @@ do_tunable_update_val (tunable_t *cur, const tunable_val_t *valp,
cur->initialized = true;
}
+static bool
+tunable_parse_num (const char *strval, size_t len, tunable_num_t *val)
+{
+ char *endptr = NULL;
+ uint64_t numval = _dl_strtoul (strval, &endptr);
+ if (endptr != strval + len)
+ return false;
+ *val = (tunable_num_t) numval;
+ return true;
+}
+
/* Validate range of the input value and initialize the tunable CUR if it looks
good. */
static bool
@@ -128,11 +139,8 @@ tunable_initialize (tunable_t *cur, const char *strval, size_t len)
if (cur->type.type_code != TUNABLE_TYPE_STRING)
{
- char *endptr = NULL;
- uint64_t numval = _dl_strtoul (strval, &endptr);
- if (endptr != strval + len)
+ if (!tunable_parse_num (strval, len, &val.numval))
return false;
- val.numval = (tunable_num_t) numval;
}
else
val.strval = (struct tunable_str_t) { strval, len };
@@ -223,17 +231,6 @@ parse_tunables_string (const char *valstring, struct tunable_toset_t *tunables)
if (tunable_is_name (cur->name, name))
{
tunables[i] = (struct tunable_toset_t) { cur, value, p - value };
-
- /* Ignore tunables if enable_secure is set */
- if (tunable_is_name ("glibc.rtld.enable_secure", name))
- {
- tunable_num_t val = (tunable_num_t) _dl_strtoul (value, NULL);
- if (val == 1)
- {
- __libc_enable_secure = 1;
- return 0;
- }
- }
break;
}
}
@@ -242,6 +239,16 @@ parse_tunables_string (const char *valstring, struct tunable_toset_t *tunables)
return ntunables;
}
+static void
+parse_tunable_print_error (const struct tunable_toset_t *toset)
+{
+ _dl_error_printf ("WARNING: ld.so: invalid GLIBC_TUNABLES value `%.*s' "
+ "for option `%s': ignored.\n",
+ (int) toset->len,
+ toset->value,
+ toset->t->name);
+}
+
static void
parse_tunables (const char *valstring)
{
@@ -253,6 +260,21 @@ parse_tunables (const char *valstring)
return;
}
+ /* Ignore tunables if enable_secure is set */
+ struct tunable_toset_t *tsec =
+ &tunables[TUNABLE_ENUM_NAME(glibc, rtld, enable_secure)];
+ if (tsec->t != NULL)
+ {
+ tunable_num_t val;
+ if (!tunable_parse_num (tsec->value, tsec->len, &val))
+ parse_tunable_print_error (tsec);
+ else if (val == 1)
+ {
+ __libc_enable_secure = 1;
+ return;
+ }
+ }
+
for (int i = 0; i < tunables_list_size; i++)
{
if (tunables[i].t == NULL)
@@ -260,11 +282,7 @@ parse_tunables (const char *valstring)
if (!tunable_initialize (tunables[i].t, tunables[i].value,
tunables[i].len))
- _dl_error_printf ("WARNING: ld.so: invalid GLIBC_TUNABLES value `%.*s' "
- "for option `%s': ignored.\n",
- (int) tunables[i].len,
- tunables[i].value,
- tunables[i].t->name);
+ parse_tunable_print_error (&tunables[i]);
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-05-07 17:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-07 17:04 [glibc] elf: Remove glibc.rtld.enable_secure check from parse_tunables_string Adhemerval Zanella
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).