libnm: handle NUL characters in nm_vpn_service_plugin_read_vpn_details() and fix test

We expect to read NUL terminated strings. Upon NUL, we should do
something. Treat it as a line break.

Fixes: 8ae9cf4698 ('Revert "libnm: buffer reads in nm_vpn_service_plugin_read_vpn_details()"')
(cherry picked from commit 6235815248)
This commit is contained in:
Thomas Haller 2022-03-28 09:40:22 +02:00 committed by Beniamino Galvani
parent 78a5c72ed6
commit cb70a15fd5
2 changed files with 14 additions and 2 deletions

View file

@ -795,6 +795,12 @@ nm_vpn_service_plugin_read_vpn_details(int fd, GHashTable **out_data, GHashTable
}
break;
}
if (nr > 0 && c == '\0') {
/* '\0' are not supported. Replace with newline. */
c = '\n';
}
if (nr > 0 && c != '\n') {
g_string_append_c(line, c);
if (line->len > 512 * 1024) {

View file

@ -2546,8 +2546,14 @@ test_nm_vpn_service_plugin_read_vpn_details(void)
"DONE\n"
"\n"
"",
READ_VPN_DETAIL_DATA({"some\nkey-2", "val2"}, {"some-key", "string"}, ),
READ_VPN_DETAIL_DATA(), );
READ_VPN_DETAIL_DATA({"some\nkey-2", "val2"},
{"some-key", "string"},
{"key3\nkey-2", "val3"}, ),
READ_VPN_DETAIL_DATA({"some-secret", "val3"},
{"key-inval", "in\xc1val"},
{"ke\xc0yx", "inval"},
{"keyx", ""},
{"", "val3"}), );
}
/*****************************************************************************/