]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/shared/util.c
shared, core: do not always accept numbers in string lookups
authorMichal Schmidt <mschmidt@redhat.com>
Tue, 30 Oct 2012 13:29:38 +0000 (14:29 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Tue, 30 Oct 2012 14:41:15 +0000 (15:41 +0100)
commitf8b69d1dfc307562a353f6aa923b7c2b915aaddb
tree79a9776e85e7f9ad9ca944665cc428be480789f3
parent26acfdae44e3605788420432d28a7264214d1213
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.
src/core/dbus-manager.c
src/core/execute.c
src/core/load-fragment.c
src/shared/socket-util.c
src/shared/socket-util.h
src/shared/util.c
src/shared/util.h