From 74c2538bb39333c1aec9f7e32e3ab3db7dcf080c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 4 Dec 2017 11:45:20 +0100 Subject: [PATCH] ifcfg-rh: use NM_STRCHAR_ANY() macro in add_one_wep_key() (cherry picked from commit da6394d5726012b963cf5610d7a9db0670f32d77) --- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 665839fbbf..d815e188f0 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -2355,29 +2355,19 @@ add_one_wep_key (shvarFile *ifcfg, } else { if (strlen (value) == 10 || strlen (value) == 26) { /* Hexadecimal WEP key */ - char *p = value; - - while (*p) { - if (!g_ascii_isxdigit (*p)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid hexadecimal WEP key."); - return FALSE; - } - p++; + if (NM_STRCHAR_ANY (value, ch, !g_ascii_isxdigit (ch))) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid hexadecimal WEP key."); + return FALSE; } key = g_strdup (value); } else if ( !strncmp (value, "s:", 2) && (strlen (value) == 7 || strlen (value) == 15)) { /* ASCII key */ - char *p = value + 2; - - while (*p) { - if (!g_ascii_isprint ((int) (*p))) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid ASCII WEP key."); - return FALSE; - } - p++; + if (NM_STRCHAR_ANY (value + 2, ch, !g_ascii_isprint (ch))) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid ASCII WEP key."); + return FALSE; } /* Remove 's:' prefix.