diff options
author | Thomas Haller <thaller@redhat.com> | 2022-03-28 09:40:22 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2022-04-29 17:26:30 +0200 |
commit | cb70a15fd5229234bf689e83d3de5ec0611a9cdf (patch) | |
tree | 247e77e6447014c3a9d1ddf2131549b8059a3864 | |
parent | 78a5c72ed650813668d730dbb4dda3b132b87a96 (diff) | |
download | NetworkManager-cb70a15fd5229234bf689e83d3de5ec0611a9cdf.tar.gz |
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: 8ae9cf4698b4 ('Revert "libnm: buffer reads in nm_vpn_service_plugin_read_vpn_details()"')
(cherry picked from commit 6235815248314c0bd3deb485692881620a859cf9)
-rw-r--r-- | src/libnm-client-impl/nm-vpn-service-plugin.c | 6 | ||||
-rw-r--r-- | src/libnm-client-impl/tests/test-libnm.c | 10 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/libnm-client-impl/nm-vpn-service-plugin.c b/src/libnm-client-impl/nm-vpn-service-plugin.c index 7b04c30799..3493d1db10 100644 --- a/src/libnm-client-impl/nm-vpn-service-plugin.c +++ b/src/libnm-client-impl/nm-vpn-service-plugin.c @@ -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) { diff --git a/src/libnm-client-impl/tests/test-libnm.c b/src/libnm-client-impl/tests/test-libnm.c index 0f600a4a01..58b71e285c 100644 --- a/src/libnm-client-impl/tests/test-libnm.c +++ b/src/libnm-client-impl/tests/test-libnm.c @@ -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"}), ); } /*****************************************************************************/ |