Add check for max val len in key:val pair

This commit is contained in:
Arun Prakash Jana 2020-01-12 08:40:33 +05:30
parent b70a54d47e
commit 7718f77069
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -2507,7 +2507,7 @@ static int xlink(char *prefix, char *path, char *curfname, char *buf, int *prese
return count;
}
static bool parsekvpair(kv *kvarr, char **envcpy, const char *cfgstr, uchar maxitems)
static bool parsekvpair(kv *kvarr, char **envcpy, const char *cfgstr, uchar maxitems, size_t maxlen)
{
int i = 0;
char *nextkey;
@ -2549,6 +2549,10 @@ static bool parsekvpair(kv *kvarr, char **envcpy, const char *cfgstr, uchar maxi
kvarr[i].key = '\0';
}
for (i = 0; i < maxitems && kvarr[i].key; ++i)
if (strlen(kvarr[i].val) >= maxlen)
return FALSE;
return TRUE;
}
@ -5932,13 +5936,13 @@ int main(int argc, char *argv[])
DPRINTF_S(opener);
/* Parse bookmarks string */
if (!parsekvpair(bookmark, &bmstr, env_cfg[NNN_BMS], BM_MAX)) {
if (!parsekvpair(bookmark, &bmstr, env_cfg[NNN_BMS], BM_MAX, PATH_MAX)) {
fprintf(stderr, "%s\n", env_cfg[NNN_BMS]);
return _FAILURE;
}
/* Parse plugins string */
if (!parsekvpair(plug, &pluginstr, "NNN_PLUG", PLUGIN_MAX)) {
if (!parsekvpair(plug, &pluginstr, "NNN_PLUG", PLUGIN_MAX, PATH_MAX)) {
fprintf(stderr, "%s\n", "NNN_PLUG");
return _FAILURE;
}