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.
This commit is contained in:
@@ -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)
|
static bool print_key(char *buf, int len, char *start, char *key, va_list args)
|
||||||
{
|
{
|
||||||
va_list copy;
|
va_list copy;
|
||||||
|
char *pos = start;
|
||||||
bool res;
|
bool res;
|
||||||
char *pos;
|
|
||||||
|
|
||||||
va_copy(copy, args);
|
va_copy(copy, args);
|
||||||
while (start < key)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
pos = strchr(start, '%');
|
pos = memchr(pos, '%', key - pos);
|
||||||
if (!pos)
|
if (!pos)
|
||||||
{
|
{
|
||||||
start += strlen(start) + 1;
|
break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
pos++;
|
pos++;
|
||||||
switch (*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);
|
DBG1(DBG_CFG, "settings with %%%c not supported!", *pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
start = pos;
|
pos++;
|
||||||
if (*start)
|
|
||||||
{
|
|
||||||
start++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
res = vsnprintf(buf, len, key, copy) < len;
|
res = vsnprintf(buf, len, key, copy) < len;
|
||||||
va_end(copy);
|
va_end(copy);
|
||||||
|
|||||||
Reference in New Issue
Block a user