diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2012-10-30 14:29:38 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2012-10-30 15:41:15 +0100 |
commit | f8b69d1dfc307562a353f6aa923b7c2b915aaddb (patch) | |
tree | 79a9776e85e7f9ad9ca944665cc428be480789f3 /src/core/load-fragment.c | |
parent | 26acfdae44e3605788420432d28a7264214d1213 (diff) |
shared, core: do not always accept numbers in string lookups
The behaviour of the common name##_from_string conversion is surprising.
It accepts not only the strings from name##_table but also any number
that falls within the range of the table. The order of items in most of
our tables is an internal affair. It should not be visible to the user.
I know of a case where the surprising numeric conversion leads to a crash.
We will allow the direct numeric conversion only for the tables where the
mapping of strings to numeric values has an external meaning. This holds
for the following lookup tables:
- netlink_family, ioprio_class, ip_tos, sched_policy - their numeric
values are stable as they are defined by the Linux kernel interface.
- log_level, log_facility_unshifted - the well-known syslog interface.
We allow the user to use numeric values whose string names systemd does
not know. For instance, the user may want to test a new kernel featuring
a scheduling policy that did not exist when his systemd version was
released. A slightly unpleasant effect of this is that the
name##_to_string conversion cannot return pointers to constant strings
anymore. The strings have to be allocated on demand and freed by the
caller.
Diffstat (limited to 'src/core/load-fragment.c')
-rw-r--r-- | src/core/load-fragment.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 2504d730dc..5803044178 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -616,7 +616,8 @@ int config_parse_exec_io_class( assert(rvalue); assert(data); - if ((x = ioprio_class_from_string(rvalue)) < 0) { + x = ioprio_class_from_string(rvalue); + if (x < 0) { log_error("[%s:%u] Failed to parse IO scheduling class, ignoring: %s", filename, line, rvalue); return 0; } @@ -675,7 +676,8 @@ int config_parse_exec_cpu_sched_policy( assert(rvalue); assert(data); - if ((x = sched_policy_from_string(rvalue)) < 0) { + x = sched_policy_from_string(rvalue); + if (x < 0) { log_error("[%s:%u] Failed to parse CPU scheduling policy, ignoring: %s", filename, line, rvalue); return 0; } @@ -1452,11 +1454,11 @@ int config_parse_ip_tos( assert(rvalue); assert(data); - if ((x = ip_tos_from_string(rvalue)) < 0) - if (safe_atoi(rvalue, &x) < 0) { - log_error("[%s:%u] Failed to parse IP TOS value, ignoring: %s", filename, line, rvalue); - return 0; - } + x = ip_tos_from_string(rvalue); + if (x < 0) { + log_error("[%s:%u] Failed to parse IP TOS value, ignoring: %s", filename, line, rvalue); + return 0; + } *ip_tos = x; return 0; |