Blame SOURCES/0463-core-simplify-parsing-of-capability-bounding-set-set.patch

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