settings: Make print_key() not rely on null-terminated beginning of key buffer
authorTobias Brunner <tobias@strongswan.org>
Tue, 28 Jan 2014 13:17:58 +0000 (14:17 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 12 Feb 2014 13:34:32 +0000 (14:34 +0100)
The key to print (e.g. until the next .) still has to be
null-terminated.

src/libstrongswan/utils/settings.c

index aa8f064..c3ab52a 100644 (file)
@@ -184,17 +184,16 @@ static bool kv_find(kv_t *this, char *key)
 static bool print_key(char *buf, int len, char *start, char *key, va_list args)
 {
        va_list copy;
+       char *pos = start;
        bool res;
-       char *pos;
 
        va_copy(copy, args);
-       while (start < key)
+       while (TRUE)
        {
-               pos = strchr(start, '%');
+               pos = memchr(pos, '%', key - pos);
                if (!pos)
                {
-                       start += strlen(start) + 1;
-                       continue;
+                       break;
                }
                pos++;
                switch (*pos)
@@ -215,11 +214,7 @@ static bool print_key(char *buf, int len, char *start, char *key, va_list args)
                                DBG1(DBG_CFG, "settings with %%%c not supported!", *pos);
                                break;
                }
-               start = pos;
-               if (*start)
-               {
-                       start++;
-               }
+               pos++;
        }
        res = vsnprintf(buf, len, key, copy) < len;
        va_end(copy);