summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-03-28 09:40:22 +0200
committerThomas Haller <thaller@redhat.com>2022-03-28 10:36:05 +0200
commit6235815248314c0bd3deb485692881620a859cf9 (patch)
tree8e190c85a7f942e1dbe5d72f2a7c1ce683d2d0bd
parent8ae9cf4698b4fadae8cfbfbc801cf93d2385629d (diff)
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()"')
-rw-r--r--src/libnm-client-impl/nm-vpn-service-plugin.c6
-rw-r--r--src/libnm-client-impl/tests/test-libnm.c10
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 d3265e9fb4..f24828f57e 100644
--- a/src/libnm-client-impl/tests/test-libnm.c
+++ b/src/libnm-client-impl/tests/test-libnm.c
@@ -2550,8 +2550,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"}), );
}
/*****************************************************************************/