From: Youngjae Cho Date: Thu, 9 Jun 2022 08:12:42 +0000 (+0900) Subject: ini-parser: check closing bracket when parsing section name X-Git-Tag: submit/tizen/20220822.111221~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F79%2F276079%2F1;p=platform%2Fcore%2Fsystem%2Flibsyscommon.git ini-parser: check closing bracket when parsing section name Change-Id: Ic939bfd6f57c9ee20e41fe7adf34f0debe3539e6 Signed-off-by: Youngjae Cho --- diff --git a/src/libcommon/ini-parser.c b/src/libcommon/ini-parser.c index f08b28a..0f145c6 100644 --- a/src/libcommon/ini-parser.c +++ b/src/libcommon/ini-parser.c @@ -166,6 +166,7 @@ int libsys_config_parse_by_section(const char *fname, int cb(const struct parse_ char tmp_sectname[128]; char tmp_key[128]; char tmp_value[128]; + char closing_bracket; if (!fname || !cb) return -EINVAL; @@ -178,16 +179,16 @@ int libsys_config_parse_by_section(const char *fname, int cb(const struct parse_ while (getline(&line, &len, fp) != EOF) { // find section - retval = sscanf_trim_whitespace_comment(line, "[%127[^]]]", tmp_sectname); - if (retval != 1) + retval = sscanf_trim_whitespace_comment(line, "[%127[^]]%c", tmp_sectname, &closing_bracket); + if (retval != 2 || closing_bracket != ']') continue; result.section = strndup(tmp_sectname, sizeof(tmp_sectname)); // parse properties within the section while((n_read = getline(&line, &len, fp)) != EOF) { - retval = sscanf_trim_whitespace_comment(line, "[%127[^]]]", tmp_sectname); - if (retval == 1) { // found next section. stop parsing properties + retval = sscanf_trim_whitespace_comment(line, "[%127[^]]%c", tmp_sectname, &closing_bracket); + if (retval == 2 && closing_bracket == ']') { // found next section. stop parsing properties fseek(fp, -n_read, SEEK_CUR); break; }