[systemd-devel] [PATCH] condition-util: do not validate condition if paramater is garbage

Ronny Chevalier chevalier.ronny at gmail.com
Sat Aug 16 05:24:26 PDT 2014


To follow the same behavior that src/core/condition.c do
---
 src/shared/condition-util.c    | 2 +-
 src/test/test-condition-util.c | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/shared/condition-util.c b/src/shared/condition-util.c
index ff4a8ec..f21786f 100644
--- a/src/shared/condition-util.c
+++ b/src/shared/condition-util.c
@@ -213,7 +213,7 @@ bool condition_test_ac_power(Condition *c) {
 
         r = parse_boolean(c->parameter);
         if (r < 0)
-                return !c->negate;
+                return c->negate;
 
         return ((on_ac_power() != 0) == !!r) == !c->negate;
 }
diff --git a/src/test/test-condition-util.c b/src/test/test-condition-util.c
index 4ee5600..3de0b67 100644
--- a/src/test/test-condition-util.c
+++ b/src/test/test-condition-util.c
@@ -38,6 +38,10 @@ static void test_condition_test_ac_power(void) {
         condition = condition_new(CONDITION_AC_POWER, "false", false, true);
         assert_se(condition_test_ac_power(condition) == on_ac_power());
         condition_free(condition);
+
+        condition = condition_new(CONDITION_AC_POWER, "garbage value", false, false);
+        assert_se(!condition_test_ac_power(condition));
+        condition_free(condition);
 }
 
 static void test_condition_test_host(void) {
-- 
2.0.4



More information about the systemd-devel mailing list