[PATCH] Fix the bug of handling complex configuration lines with mixed "" and #

xinpeng wang wangxinpeng at uniontech.com
Mon Sep 13 22:09:20 PDT 2021


The original code wants to Remove # comments unless they are within a double quoted string, but it doesn’t consider the "" after #,
for example a=b #"a=c"

Signed-off-by: xinpeng wang <wangxinpeng at uniontech.com>
---
 src/utils/config.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/utils/config.c b/src/utils/config.c
index 22aa2216e..ec4fa9a59 100644
--- a/src/utils/config.c
+++ b/src/utils/config.c
@@ -66,12 +66,21 @@ 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
-- 
2.20.1






More information about the Hostap mailing list