From f42c3d6653e7ba54f57850f9733bcc65758947c2 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 16 Jul 2018 13:02:24 +0200 Subject: service-plugin: add a warning here and there We're basically rather careless when parsing the auth-dialog protocol. Let's add some warning so we get an early alert when something's wrong. --- libnm/nm-vpn-service-plugin.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libnm/nm-vpn-service-plugin.c b/libnm/nm-vpn-service-plugin.c index 94a1ebbc04..8d6c43a260 100644 --- a/libnm/nm-vpn-service-plugin.c +++ b/libnm/nm-vpn-service-plugin.c @@ -843,25 +843,37 @@ nm_vpn_service_plugin_read_vpn_details (int fd, /* finish marker */ break; } else if (strncmp (line->str, DATA_KEY_TAG, strlen (DATA_KEY_TAG)) == 0) { - if (key != NULL) + if (key != NULL) { + g_warning ("a value expected"); g_string_free (key, TRUE); + } key = g_string_new (line->str + strlen (DATA_KEY_TAG)); str = key; hash = data; } else if (strncmp (line->str, DATA_VAL_TAG, strlen (DATA_VAL_TAG)) == 0) { if (val != NULL) g_string_free (val, TRUE); + if (val || !key || hash != data) { + g_warning ("%s not preceded by %s", DATA_VAL_TAG, DATA_KEY_TAG); + break; + } val = g_string_new (line->str + strlen (DATA_VAL_TAG)); str = val; } else if (strncmp (line->str, SECRET_KEY_TAG, strlen (SECRET_KEY_TAG)) == 0) { - if (key != NULL) + if (key != NULL) { + g_warning ("a value expected"); g_string_free (key, TRUE); + } key = g_string_new (line->str + strlen (SECRET_KEY_TAG)); str = key; hash = secrets; } else if (strncmp (line->str, SECRET_VAL_TAG, strlen (SECRET_VAL_TAG)) == 0) { if (val != NULL) g_string_free (val, TRUE); + if (val || !key || hash != secrets) { + g_warning ("%s not preceded by %s", SECRET_VAL_TAG, SECRET_KEY_TAG); + break; + } val = g_string_new (line->str + strlen (SECRET_VAL_TAG)); str = val; } -- cgit v1.2.1