[systemd-commits] 3 commits - src/core src/shared

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Mon Nov 19 08:14:30 PST 2012


 src/core/load-fragment.c |   86 +++++++++++++++++++++++------------------------
 src/shared/util.c        |    4 +-
 2 files changed, 45 insertions(+), 45 deletions(-)

New commits:
commit ac97e2c559f5d386a332aba4a24bf9930cdb1c51
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Nov 19 16:36:38 2012 +0100

    core/load-fragment: fix (potential) bad memory access
    
    strncmp() could be used with size bigger then the size of the string,
    because MAX was used instead of MIN.
    
    If failing, print just the offending mount flag.

diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 01f9484..6933e1a 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -1101,15 +1101,22 @@ int config_parse_exec_mount_flags(
         assert(rvalue);
         assert(data);
 
-        FOREACH_WORD_QUOTED(w, l, rvalue, state) {
-                if (strncmp(w, "shared", MAX(l, 6U)) == 0)
+        FOREACH_WORD_SEPARATOR(w, l, rvalue, ", ", state) {
+                char _cleanup_free_ *t;
+
+                t = strndup(w, l);
+                if (!t)
+                        return -ENOMEM;
+
+                if (streq(t, "shared"))
                         flags |= MS_SHARED;
-                else if (strncmp(w, "slave", MAX(l, 5U)) == 0)
+                else if (streq(t, "slave"))
                         flags |= MS_SLAVE;
-                else if (strncmp(w, "private", MAX(l, 7U)) == 0)
+                else if (streq(w, "private"))
                         flags |= MS_PRIVATE;
                 else {
-                        log_error("[%s:%u] Failed to parse mount flags, ignoring: %s", filename, line, rvalue);
+                        log_error("[%s:%u] Failed to parse mount flag %s, ignoring: %s",
+                                  filename, line, t, rvalue);
                         return 0;
                 }
         }

commit c040936be2a4c77e9465cffae47d77d5ec14fb49
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Nov 19 16:02:45 2012 +0100

    core/load-fragment: be more precise in error messages
    
    Whenever a message fails, mention the offending word, instead
    of just giving the whole line. If one bad word causes just this
    word to be rejected, print only the word. If one bad word causes
    the whole line to be rejected, print the whole line too.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=56874

diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 6759255..01f9484 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -86,7 +86,7 @@ int config_parse_unit_deps(
         assert(rvalue);
 
         FOREACH_WORD_QUOTED(w, l, rvalue, state) {
-                char *t, *k;
+                char _cleanup_free_ *t = NULL, *k = NULL;
                 int r;
 
                 t = strndup(w, l);
@@ -94,15 +94,13 @@ int config_parse_unit_deps(
                         return -ENOMEM;
 
                 k = unit_name_printf(u, t);
-                free(t);
                 if (!k)
                         return -ENOMEM;
 
                 r = unit_add_dependency_by_name(u, d, k, NULL, true);
                 if (r < 0)
-                        log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", filename, line, k, strerror(-r));
-
-                free(k);
+                        log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s",
+                                  filename, line, k, strerror(-r));
         }
 
         return 0;
@@ -757,22 +755,25 @@ int config_parse_exec_cpu_affinity(
         assert(data);
 
         FOREACH_WORD_QUOTED(w, l, rvalue, state) {
-                char *t;
+                char _cleanup_free_ *t = NULL;
                 int r;
                 unsigned cpu;
 
-                if (!(t = strndup(w, l)))
+                t = strndup(w, l);
+                if (!t)
                         return -ENOMEM;
 
                 r = safe_atou(t, &cpu);
-                free(t);
 
-                if (!(c->cpuset))
-                        if (!(c->cpuset = cpu_set_malloc(&c->cpuset_ncpus)))
+                if (!c->cpuset) {
+                        c->cpuset = cpu_set_malloc(&c->cpuset_ncpus);
+                        if (!c->cpuset)
                                 return -ENOMEM;
+                }
 
                 if (r < 0 || cpu >= c->cpuset_ncpus) {
-                        log_error("[%s:%u] Failed to parse CPU affinity, ignoring: %s", filename, line, rvalue);
+                        log_error("[%s:%u] Failed to parse CPU affinity %s, ignoring: %s",
+                                  filename, line, t, rvalue);
                         return 0;
                 }
 
@@ -849,7 +850,8 @@ int config_parse_exec_secure_bits(
                 else if (first_word(w, "noroot-locked"))
                         c->secure_bits |= SECURE_NOROOT_LOCKED;
                 else {
-                        log_error("[%s:%u] Failed to parse secure bits, ignoring: %s", filename, line, rvalue);
+                        log_error("[%s:%u] Failed to parse secure bits, ignoring: %s",
+                                  filename, line, rvalue);
                         return 0;
                 }
         }
@@ -890,7 +892,7 @@ int config_parse_bounding_set(
          * interface. */
 
         FOREACH_WORD_QUOTED(w, l, rvalue, state) {
-                char *t;
+                char _cleanup_free_ *t = NULL;
                 int r;
                 cap_value_t cap;
 
@@ -899,10 +901,9 @@ int config_parse_bounding_set(
                         return -ENOMEM;
 
                 r = cap_from_name(t, &cap);
-                free(t);
-
                 if (r < 0) {
-                        log_error("[%s:%u] Failed to parse capability bounding set, ignoring: %s", filename, line, rvalue);
+                        log_error("[%s:%u] Failed to parse capability in bounding set, ignoring: %s",
+                                  filename, line, t);
                         continue;
                 }
 
@@ -968,7 +969,7 @@ int config_parse_unit_cgroup(
         char *state;
 
         FOREACH_WORD_QUOTED(w, l, rvalue, state) {
-                char *t, *k;
+                char _cleanup_free_ *t = NULL, *k = NULL, *ku = NULL;
                 int r;
 
                 t = strndup(w, l);
@@ -976,22 +977,17 @@ int config_parse_unit_cgroup(
                         return -ENOMEM;
 
                 k = unit_full_printf(u, t);
-                free(t);
-
                 if (!k)
                         return -ENOMEM;
 
-                t = cunescape(k);
-                free(k);
-
-                if (!t)
+                ku = cunescape(k);
+                if (!ku)
                         return -ENOMEM;
 
-                r = unit_add_cgroup_from_text(u, t);
-                free(t);
-
+                r = unit_add_cgroup_from_text(u, ku);
                 if (r < 0) {
-                        log_error("[%s:%u] Failed to parse cgroup value, ignoring: %s", filename, line, rvalue);
+                        log_error("[%s:%u] Failed to parse cgroup value %s, ignoring: %s",
+                                  filename, line, k, rvalue);
                         return 0;
                 }
         }
@@ -1351,33 +1347,30 @@ int config_parse_service_sockets(
         assert(data);
 
         FOREACH_WORD_QUOTED(w, l, rvalue, state) {
-                char *t, *k;
+                char _cleanup_free_ *t = NULL, *k = NULL;
 
                 t = strndup(w, l);
                 if (!t)
                         return -ENOMEM;
 
                 k = unit_name_printf(UNIT(s), t);
-                free(t);
-
                 if (!k)
                         return -ENOMEM;
 
                 if (!endswith(k, ".socket")) {
-                        log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue);
-                        free(k);
+                        log_error("[%s:%u] Unit must be of type socket, ignoring: %s",
+                                  filename, line, k);
                         continue;
                 }
 
                 r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k, NULL, true);
                 if (r < 0)
-                        log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", filename, line, k, strerror(-r));
+                        log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s",
+                                  filename, line, k, strerror(-r));
 
                 r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k, NULL, true);
                 if (r < 0)
                         return r;
-
-                free(k);
         }
 
         return 0;
@@ -2105,17 +2098,17 @@ int config_parse_syscall_filter(
 
         FOREACH_WORD_QUOTED(w, l, rvalue, state) {
                 int id;
-                char *t;
+                char _cleanup_free_ *t = NULL;
 
                 t = strndup(w, l);
                 if (!t)
                         return -ENOMEM;
 
                 id = syscall_from_name(t);
-                free(t);
 
                 if (id < 0)  {
-                        log_error("[%s:%u] Failed to parse syscall, ignoring: %s", filename, line, rvalue);
+                        log_error("[%s:%u] Failed to parse syscall, ignoring: %s",
+                                  filename, line, t);
                         continue;
                 }
 

commit 7009eec20823add711e0aa452bdf9dfdd677fa4f
Author: Anders Olofsson <anders.olofsson at axis.com>
Date:   Mon Nov 19 15:25:36 2012 +0100

    shared/utils: systemd-cgls shows 'n/a' when piping output
    
    -1 was used to signal failure, but the type was unsigned.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=56644

diff --git a/src/shared/util.c b/src/shared/util.c
index 4cf928f..d771d32 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3803,7 +3803,7 @@ int fd_columns(int fd) {
 
 unsigned columns(void) {
         const char *e;
-        unsigned c;
+        int c;
 
         if (_likely_(cached_columns > 0))
                 return cached_columns;
@@ -3811,7 +3811,7 @@ unsigned columns(void) {
         c = 0;
         e = getenv("COLUMNS");
         if (e)
-                safe_atou(e, &c);
+                safe_atoi(e, &c);
 
         if (c <= 0)
                 c = fd_columns(STDOUT_FILENO);



More information about the systemd-commits mailing list