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