]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Fix handling of complex configuration lines with mixed "" and #
authorxinpeng wang <wangxinpeng@uniontech.com>
Tue, 14 Sep 2021 05:09:20 +0000 (13:09 +0800)
committerJouni Malinen <j@w1.fi>
Fri, 22 Oct 2021 14:47:29 +0000 (17:47 +0300)
The original code wants to remove # comments unless they are within a
double quoted string, but it doesn’t consider the "" after #, for
example in the following line: a=b #"a=c"

Signed-off-by: xinpeng wang <wangxinpeng@uniontech.com>
src/utils/config.c

index 22aa2216eb3f4055827102d257c357046ba0cdd6..ba26c2c9a71c488867c9f4fd7b64bb290a5116c0 100644 (file)
@@ -66,12 +66,20 @@ char * wpa_config_get_line(char *s, int size, FILE *stream, int *line,
                 * Remove # comments unless they are within a double quoted
                 * string.
                 */
-               sstart = os_strchr(pos, '"');
-               if (sstart)
-                       sstart = os_strrchr(sstart + 1, '"');
-               if (!sstart)
-                       sstart = pos;
+               sstart = pos;
                end = os_strchr(sstart, '#');
+               while (end) {
+                       sstart = os_strchr(sstart, '"');
+                       if (!sstart || sstart > end)
+                               break;
+                       sstart = os_strchr(sstart + 1, '"');
+                       if (!sstart)
+                               break;
+                       sstart++;
+                       if (sstart > end)
+                               end = os_strchr(sstart, '#');
+               }
+
                if (end)
                        *end-- = '\0';
                else