chiark / gitweb /
parse_boolean: require exact matches
authorAnsgar Burchardt <ansgar@debian.org>
Sun, 27 Jul 2014 13:19:00 +0000 (15:19 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 27 Jul 2014 19:15:11 +0000 (15:15 -0400)
Require exact matches in all cases instead of treating strings
starting with 't' ('f') as true (false).

This is required for config_parse_protect_system to parse ProtectSystem=full
correctly: it uses parse_boolean and only tries a more specific parsing
function if that did not return a valid result. Thus "full" was treated as
"false" before.

src/shared/util.c
src/test/test-util.c

index 4fda31c83832de5cd34efd99800e0da0f35dbeaf..49c17eff85fdfa4137cf75551f250cb4068bd537 100644 (file)
@@ -231,9 +231,9 @@ int unlink_noerrno(const char *path) {
 int parse_boolean(const char *v) {
         assert(v);
 
-        if (streq(v, "1") || v[0] == 'y' || v[0] == 'Y' || v[0] == 't' || v[0] == 'T' || strcaseeq(v, "on"))
+        if (streq(v, "1") || strcaseeq(v, "yes") || strcaseeq(v, "y") || strcaseeq(v, "true") || strcaseeq(v, "t") || strcaseeq(v, "on"))
                 return 1;
-        else if (streq(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || strcaseeq(v, "off"))
+        else if (streq(v, "0") || strcaseeq(v, "no") || strcaseeq(v, "n") || strcaseeq(v, "false") || strcaseeq(v, "f") || strcaseeq(v, "off"))
                 return 0;
 
         return -EINVAL;
index ed91a67d10f25bbb4aa7a4f4d07d9515c4c27997..9a28ef9eec4a2d73075ab50acf4fec523f31ca73 100644 (file)
@@ -129,6 +129,7 @@ static void test_parse_boolean(void) {
 
         assert_se(parse_boolean("garbage") < 0);
         assert_se(parse_boolean("") < 0);
+        assert_se(parse_boolean("full") < 0);
 }
 
 static void test_parse_pid(void) {