Fix handling of complex configuration lines with mixed "" and #

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>
This commit is contained in:
xinpeng wang 2021-09-14 13:09:20 +08:00 committed by Jouni Malinen
parent 0ae677c7b4
commit aca4d4963a

View 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 * Remove # comments unless they are within a double quoted
* string. * string.
*/ */
sstart = os_strchr(pos, '"');
if (sstart)
sstart = os_strrchr(sstart + 1, '"');
if (!sstart)
sstart = pos; sstart = pos;
end = os_strchr(sstart, '#'); 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) if (end)
*end-- = '\0'; *end-- = '\0';
else else