From 03d80950e960031af977c3037b57d41e36701fb2 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Sat, 18 Feb 2012 20:03:33 -0500 Subject: [PATCH] ifnet: do not truncate WPA passwords at '#' character We need to do the same thing as wpa_supplicant's own config file parser and ignore '#' characters that occur between the first and last '"' characters in a config file line. https://bugzilla.gnome.org/show_bug.cgi?id=670381 --- src/settings/plugins/ifnet/wpa_parser.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/settings/plugins/ifnet/wpa_parser.c b/src/settings/plugins/ifnet/wpa_parser.c index da2bc3b..f7a5b32 100644 --- a/src/settings/plugins/ifnet/wpa_parser.c +++ b/src/settings/plugins/ifnet/wpa_parser.c @@ -279,16 +279,21 @@ wpa_parser_init (const char *wpa_supplicant_conf) } else { GHashTable *network = g_hash_table_new (g_str_hash, g_str_equal); - gchar *tmp; do { + gchar *quote_start, *quote_end = NULL, *comment; + if (line[0] == '#' || line[0] == '\0') { g_free (line); continue; } - /* ignore inline comments */ - if ((tmp = strchr (line, '#')) != NULL) - *tmp = '\0'; + /* ignore inline comments unless inside + a double-quoted string */ + if ((quote_start = strchr (line, '"')) != NULL) + quote_end = strrchr (quote_start + 1, '"'); + if ((comment = strchr ((quote_end != NULL) ? + quote_end : line, '#')) != NULL) + *comment = '\0'; if (strstr (line, "}") != NULL) complete = TRUE; add_key_value (network, line); -- 1.7.8.4