From: Tobias Brunner Date: Tue, 28 Jan 2014 13:17:58 +0000 (+0100) Subject: settings: Make print_key() not rely on null-terminated beginning of key buffer X-Git-Tag: 5.1.2rc1~7^2~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef72d4cc3f887f4b1dc1d84304c22564db102a48;p=thirdparty%2Fstrongswan.git 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. --- diff --git a/src/libstrongswan/utils/settings.c b/src/libstrongswan/utils/settings.c index aa8f064d52..c3ab52a0e0 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);