richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
a19bc6
From 044455df76969ad26dfdcfa186e5ce81beb5b527 Mon Sep 17 00:00:00 2001
a19bc6
From: Lennart Poettering <lennart@poettering.net>
a19bc6
Date: Tue, 10 Nov 2015 16:08:03 +0100
a19bc6
Subject: [PATCH] core: simplify parsing of capability bounding set settings
a19bc6
a19bc6
Let's generate a simple error, and that's it. Let's not try to be smart
a19bc6
and record the last word that failed.
a19bc6
a19bc6
Also, let's make sure we don't compare numeric values with 0 by relying
a19bc6
on C's downgrade-to-bool feature, as suggested in CODING_STYLE.
a19bc6
a19bc6
Cherry-picked from: 65dce26488030eff078c498673d5d93e3c87b6a1
a19bc6
Resolves: #1387398
a19bc6
---
23b3cf
 src/core/load-fragment.c | 42 ++++++++++++++++++----------------------
a19bc6
 1 file changed, 19 insertions(+), 23 deletions(-)
a19bc6
a19bc6
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
c62b8e
index 4830d7ad6f..ab3b0c2e92 100644
a19bc6
--- a/src/core/load-fragment.c
a19bc6
+++ b/src/core/load-fragment.c
a19bc6
@@ -1015,23 +1015,22 @@ int config_parse_exec_secure_bits(const char *unit,
a19bc6
         return 0;
a19bc6
 }
a19bc6
 
a19bc6
-int config_parse_bounding_set(const char *unit,
a19bc6
-                              const char *filename,
a19bc6
-                              unsigned line,
a19bc6
-                              const char *section,
a19bc6
-                              unsigned section_line,
a19bc6
-                              const char *lvalue,
a19bc6
-                              int ltype,
a19bc6
-                              const char *rvalue,
a19bc6
-                              void *data,
a19bc6
-                              void *userdata) {
a19bc6
+int config_parse_bounding_set(
a19bc6
+                const char *unit,
a19bc6
+                const char *filename,
a19bc6
+                unsigned line,
a19bc6
+                const char *section,
a19bc6
+                unsigned section_line,
a19bc6
+                const char *lvalue,
a19bc6
+                int ltype,
a19bc6
+                const char *rvalue,
a19bc6
+                void *data,
a19bc6
+                void *userdata) {
a19bc6
 
a19bc6
         uint64_t *capability_bounding_set_drop = data;
a19bc6
-        uint64_t capability_bounding_set;
a19bc6
+        uint64_t capability_bounding_set, sum = 0;
a19bc6
         bool invert = false;
a19bc6
-        uint64_t sum = 0;
a19bc6
-        const char *prev;
a19bc6
-        const char *cur;
a19bc6
+        const char *p;
a19bc6
 
a19bc6
         assert(filename);
a19bc6
         assert(lvalue);
a19bc6
@@ -1048,35 +1047,32 @@ int config_parse_bounding_set(const char *unit,
a19bc6
          * non-inverted everywhere to have a fully normalized
a19bc6
          * interface. */
a19bc6
 
a19bc6
-        prev = cur = rvalue;
a19bc6
+        p = rvalue;
a19bc6
         for (;;) {
a19bc6
                 _cleanup_free_ char *word = NULL;
a19bc6
-                int cap;
a19bc6
-                int r;
a19bc6
+                int cap, r;
a19bc6
 
a19bc6
-                r = extract_first_word(&cur, &word, NULL, EXTRACT_QUOTES);
a19bc6
+                r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES);
a19bc6
                 if (r == 0)
a19bc6
                         break;
a19bc6
                 if (r == -ENOMEM)
a19bc6
                         return log_oom();
a19bc6
                 if (r < 0) {
a19bc6
-                        log_syntax(unit, LOG_ERR, filename, line, r, "Trailing garbage in bounding set, ignoring: %s", prev);
a19bc6
+                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse word, ignoring: %s", rvalue);
a19bc6
                         break;
a19bc6
                 }
a19bc6
 
a19bc6
                 cap = capability_from_name(word);
a19bc6
                 if (cap < 0) {
a19bc6
                         log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse capability in bounding set, ignoring: %s", word);
a19bc6
-                        prev = cur;
a19bc6
                         continue;
a19bc6
                 }
a19bc6
 
a19bc6
-                sum |= ((uint64_t) 1ULL) << (uint64_t) cap;
a19bc6
-                prev = cur;
a19bc6
+                sum |= ((uint64_t) UINT64_C(1)) << (uint64_t) cap;
a19bc6
         }
a19bc6
 
a19bc6
         capability_bounding_set = invert ? ~sum : sum;
a19bc6
-        if (*capability_bounding_set_drop && capability_bounding_set)
a19bc6
+        if (*capability_bounding_set_drop != 0 && capability_bounding_set != 0)
a19bc6
                 *capability_bounding_set_drop = ~(~*capability_bounding_set_drop | capability_bounding_set);
a19bc6
         else
a19bc6
                 *capability_bounding_set_drop = ~capability_bounding_set;