ini-parser: check closing bracket when parsing section name 12/276312/1
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 9 Jun 2022 08:12:42 +0000 (17:12 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 14 Jun 2022 09:28:24 +0000 (09:28 +0000)
Change-Id: Ic939bfd6f57c9ee20e41fe7adf34f0debe3539e6
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
(cherry picked from commit 64006e638e2f1151d400490ca99ea6c96ddd0de1)

src/libcommon/ini-parser.c

index f08b28a2660b40f9fd63acfe108d12cd63cca702..0f145c6197a99ad9e1876d2e39d149260c8008e1 100644 (file)
@@ -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;
                        }