]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
vici: Return default value for get_int() if message value is empty string
authorMartin Willi <martin@revosec.ch>
Tue, 14 Oct 2014 10:13:32 +0000 (12:13 +0200)
committerMartin Willi <martin@revosec.ch>
Tue, 14 Oct 2014 14:33:10 +0000 (16:33 +0200)
This is the behavior of some strtol() implementations, and it makes sense,
so force it.

src/libcharon/plugins/vici/suites/test_message.c
src/libcharon/plugins/vici/vici_message.c

index 29311734862ce11aa44c1c59cac59b2593dcf160..e76d273327aa9b7ed0b88ed055afc9cadcae8a5b 100644 (file)
@@ -347,7 +347,7 @@ START_TEST(test_get_int)
        ck_assert_int_eq(m->get_int(m, 2, "section1.key2"), 0x12);
        ck_assert_int_eq(m->get_int(m, 2, "section1.section2.key3"), -1);
        ck_assert_int_eq(m->get_int(m, 2, "section1.key4"), 2);
-       ck_assert_int_eq(m->get_int(m, 2, "key5"), 0);
+       ck_assert_int_eq(m->get_int(m, 2, "key5"), 2);
        ck_assert_int_eq(m->get_int(m, 2, "nonexistent"), 2);
        ck_assert_int_eq(m->get_int(m, 2, "n.o.n.e.x.i.s.t.e.n.t"), 2);
 
index dcc175f67cf9ca97c47cb51fd6f3961ca968cc37..e79fbc8d36cbd086719aedf2c1670fa2a00c2000 100644 (file)
@@ -355,6 +355,10 @@ METHOD(vici_message_t, vget_int, int,
        found = find_value(this, &value, fmt, args);
        if (found)
        {
+               if (value.len == 0)
+               {
+                       return def;
+               }
                if (chunk_printable(value, NULL, 0))
                {
                        snprintf(buf, sizeof(buf), "%.*s", (int)value.len, value.ptr);