From 2cc55aa09bbf746dd15e9be1c0d620a84c3984f4 Mon Sep 17 00:00:00 2001 From: Mark Lindner Date: Sat, 19 Jun 2021 17:58:28 -0600 Subject: [PATCH] fixed implementation of config_setting_lookup() to correctly return NULL instead of the passed-in setting if the specified path was not found --- ChangeLog | 5 ++++- lib/libconfig.c | 10 ++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa75d4c..6e4b809 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,7 +3,10 @@ 2021-06-19 Mark Lindner - * 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 diff --git a/lib/libconfig.c b/lib/libconfig.c index c14884c..2f3cbfa 100644 --- a/lib/libconfig.c +++ b/lib/libconfig.c @@ -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(;;) { @@ -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); } /* ------------------------------------------------------------------------- */