Skip to content

Commit

Permalink
fixed implementation of config_setting_lookup() to correctly return
Browse files Browse the repository at this point in the history
NULL instead of the passed-in setting if the specified path was not
found
  • Loading branch information
hyperrealm committed Jun 19, 2021
1 parent fa7024b commit 2cc55aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 4 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

2021-06-19 Mark Lindner <markl@avalon>

* lib/libconfig.c - Fixed double-free of config->filenames
* lib/libconfig.c - Fixed double-free of config->filenames;
fixed implementation of config_setting_lookup() to correctly return
NULL instead of the passed-in setting if the specified path was not
found
* configure.ac, lib/Makefile.am - bump version numbers

2021-04-28 Mark Lindner <markl@avalon>
Expand Down
10 changes: 4 additions & 6 deletions lib/libconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ config_setting_t *config_setting_lookup(config_setting_t *setting,
const char *path)
{
const char *p = path;
config_setting_t *found;
config_setting_t *found = setting;

for(;;)
{
Expand All @@ -1229,20 +1229,18 @@ config_setting_t *config_setting_lookup(config_setting_t *setting,
break;

if(*p == '[')
found = config_setting_get_elem(setting, atoi(++p));
found = config_setting_get_elem(found, atoi(++p));
else
found = config_setting_get_member(setting, p);
found = config_setting_get_member(found, p);

if(! found)
break;

setting = found;

while(! strchr(PATH_TOKENS, *p))
p++;
}

return(*p ? NULL : setting);
return(*p || (found == setting) ? NULL : found);
}

/* ------------------------------------------------------------------------- */
Expand Down

0 comments on commit 2cc55aa

Please sign in to comment.