From ef72d4cc3f887f4b1dc1d84304c22564db102a48 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 28 Jan 2014 14:17:58 +0100 Subject: [PATCH] settings: Make print_key() not rely on null-terminated beginning of key buffer The key to print (e.g. until the next .) still has to be null-terminated. --- src/libstrongswan/utils/settings.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/libstrongswan/utils/settings.c b/src/libstrongswan/utils/settings.c index aa8f064..c3ab52a 100644 --- a/src/libstrongswan/utils/settings.c +++ b/src/libstrongswan/utils/settings.c @@ -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); -- 2.7.4