wpa_supplicant can generate configs which it can't read back
Morten Hauke Solvang
mhs at emlogic.no
Tue Aug 6 01:31:37 PDT 2024
Hi,
I believe this commit introduces a bug:
https://w1.fi/cgit/hostap/commit/src/utils/config.c?id=aca4d4963a65e49614ed8cd52836a2619775c1f6
Take for example this password:
secret"#123
If you configure this password using wpa_cli, and save to a config file:
wpa_cli set_network 0 psk '"secret"#123"'
wpa_cli save_config
It generates a config file which looks something like this:
network={
psk="secret"#123"
}
When restarting supplicant (or doing wpa_cli reconfigure), supplicant fails to read this config back,
because wpa_config_get_line uses strchr in a loop to find pairs of quotes, and checks if the # is
inside a pair of quotes:
end of string
|
v
psk="secret"#123"
^ ^^^^^
| comment
start of string
But this doesn't match the way quotes are interpreted by the rest of the parser! If we look at
wpa_config_parse_str which calls wpa_config_parse_string, it strips the leftmost and rightmost
quote (using strrchr).
end of string
|
v
psk="secret"#123"
^
|
start of string
(Of course, wpa_config_parse_string never gets to see anything past the #, since wpa_config_get_line
already has discarded that part of the string, since it thought it was a comment).
I'd suggest reverting the commit mentioned above.
Alternatively, if the config format needs to support comments containing quotes, the config format
maybe needs to be changed to escape quotes inside quotes (instead of using strrchr)?
Best regards,
Morten Solvang
More information about the Hostap
mailing list