libnm: fix endless loop in nm_vpn_service_plugin_read_vpn_details()

Previously, a "DONE\n" was required to break the loop.
This commit is contained in:
Thomas Haller 2018-09-08 14:45:52 +02:00
parent 21f94e9265
commit 9bc33a687e
2 changed files with 10 additions and 9 deletions

View file

@ -810,15 +810,14 @@ nm_vpn_service_plugin_read_vpn_details (int fd,
errno = 0;
nr = read (fd, &c, 1);
if (nr == -1) {
if (nr < 0) {
if (errno == EAGAIN) {
g_usleep (100);
continue;
}
break;
}
if (c != '\n') {
if (nr > 0 && c != '\n') {
g_string_append_c (line, c);
continue;
}
@ -879,6 +878,9 @@ nm_vpn_service_plugin_read_vpn_details (int fd,
}
g_string_truncate (line, 0);
if (nr == 0)
break;
}
if (success) {

View file

@ -2295,12 +2295,12 @@ _do_read_vpn_details_impl1 (const char *file,
static void
test_nm_vpn_service_plugin_read_vpn_details (void)
{
//_do_read_vpn_details_empty ("");
//_do_read_vpn_details_empty ("hallo");
//_do_read_vpn_details_empty ("DONE");
_do_read_vpn_details_empty ("");
_do_read_vpn_details_empty ("hallo");
_do_read_vpn_details_empty ("DONE");
_do_read_vpn_details_empty ("DONE\n");
//_do_read_vpn_details_empty ("DONE\0");
//_do_read_vpn_details_empty ("\0DONE\0");
_do_read_vpn_details_empty ("DONE\0");
_do_read_vpn_details_empty ("\0DONE\0");
_do_read_vpn_details (""
"DATA_KEY=some-key\n"
@ -2375,7 +2375,6 @@ test_nm_vpn_service_plugin_read_vpn_details (void)
"=can have\n"
"=continuations too\n"
"SECRET_VAL=value\n"
"DONE\n"
"",
READ_VPN_DETAIL_DATA (
{ "some-key", "string\ncontinued after a line break" },