all: Don't use ctype.h macros

The ctype macros (eg, isalnum(), tolower()) are locale-dependent. Use
glib's ASCII-only versions instead.

Also, replace isascii() with g_ascii_isprint(), since isascii()
accepts control characters, which isn't what the code wanted in any of
the places where it was using it.
This commit is contained in:
Dan Winship 2012-09-25 10:44:23 -04:00
parent 74b6b9c768
commit 6878d20ac4
26 changed files with 34 additions and 60 deletions

View file

@ -22,7 +22,6 @@
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <glib.h>
#include <glib-object.h>

View file

@ -19,7 +19,6 @@
*/
#include <config.h>
#include <ctype.h>
#include <string.h>
#include <dbus/dbus-glib-lowlevel.h>
@ -766,7 +765,7 @@ validate_identifier (const char *identifier)
/* FIXME: do complete validation here */
while (p && *p) {
if (!isalnum (*p) && (*p != '_') && (*p != '-') && (*p != '.'))
if (!g_ascii_isalnum (*p) && (*p != '_') && (*p != '-') && (*p != '.'))
return FALSE;
if ((*p == '.') && (*(p + 1) == '.'))
return FALSE;

View file

@ -24,7 +24,6 @@
*/
#include <string.h>
#include <ctype.h>
#include <dbus/dbus-glib.h>
#include "nm-setting-8021x.h"
#include "nm-param-spec-specialized.h"

View file

@ -25,7 +25,6 @@
*/
#include <string.h>
#include <ctype.h>
#include <net/ethernet.h>
#include "nm-param-spec-specialized.h"

View file

@ -22,7 +22,6 @@
*/
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <dbus/dbus-glib.h>

View file

@ -24,7 +24,6 @@
*/
#include <string.h>
#include <ctype.h>
#include "nm-setting-gsm.h"
#include "nm-utils.h"
#include "nm-setting-private.h"
@ -306,7 +305,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
* like space ( ) and such.
*/
for (i = 0; i < apn_len; i++) {
if ( !isalnum (priv->apn[i])
if ( !g_ascii_isalnum (priv->apn[i])
&& (priv->apn[i] != '.')
&& (priv->apn[i] != '_')
&& (priv->apn[i] != '-')) {
@ -349,7 +348,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
for (i = 0; i < nid_len; i++) {
if (!isdigit (priv->network_id[i])) {
if (!g_ascii_isdigit (priv->network_id[i])) {
g_set_error (error,
NM_SETTING_GSM_ERROR,
NM_SETTING_GSM_ERROR_INVALID_PROPERTY,

View file

@ -24,7 +24,6 @@
*/
#include <string.h>
#include <ctype.h>
#include <net/ethernet.h>
#include <dbus/dbus-glib.h>
#include <netinet/ether.h>

View file

@ -25,7 +25,6 @@
#include <config.h>
#include <string.h>
#include <ctype.h>
#include <dbus/dbus-glib.h>
#include "nm-setting-wireless-security.h"
#include "nm-setting-8021x.h"
@ -704,13 +703,13 @@ verify_wep_key (const char *key, NMWepKeyType wep_type)
if (keylen == 10 || keylen == 26) {
/* Hex key */
for (i = 0; i < keylen; i++) {
if (!isxdigit (key[i]))
if (!g_ascii_isxdigit (key[i]))
return FALSE;
}
} else if (keylen == 5 || keylen == 13) {
/* ASCII key */
for (i = 0; i < keylen; i++) {
if (!isascii (key[i]))
if (!g_ascii_isprint (key[i]))
return FALSE;
}
} else
@ -739,7 +738,7 @@ verify_wpa_psk (const char *psk)
if (psklen == 64) {
/* Hex PSK */
for (i = 0; i < psklen; i++) {
if (!isxdigit (psk[i]))
if (!g_ascii_isxdigit (psk[i]))
return FALSE;
}
}

View file

@ -25,7 +25,6 @@
*/
#include "config.h"
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@ -2504,11 +2503,11 @@ nm_utils_hwaddr_aton (const char *asc, int type, gpointer buffer)
while (left && *in) {
guint8 d1 = in[0], d2 = in[1];
if (!isxdigit (d1))
if (!g_ascii_isxdigit (d1))
return NULL;
/* If there's no leading zero (ie "aa:b:cc") then fake it */
if (d2 && isxdigit (d2)) {
if (d2 && g_ascii_isxdigit (d2)) {
*out++ = (HEXVAL (d1) << 4) + HEXVAL (d2);
in += 2;
} else {
@ -2607,7 +2606,7 @@ nm_utils_iface_valid_name (const char *name)
return FALSE;
while (*name) {
if (*name == '/' || isspace (*name))
if (*name == '/' || g_ascii_isspace (*name))
return FALSE;
name++;
}
@ -2632,7 +2631,7 @@ nm_utils_is_uuid (const char *str)
while (*p) {
if (*p == '-')
num_dashes++;
else if (!isxdigit (*p))
else if (!g_ascii_isxdigit (*p))
return FALSE;
p++;
}

View file

@ -24,7 +24,6 @@
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include "NetworkManagerUtils.h"
@ -410,12 +409,12 @@ parse_subchannels (const char *subchannels, guint32 *a, guint32 *b, guint32 *c)
g_return_val_if_fail (*c == 0, FALSE);
/* sanity check */
if (!isxdigit (subchannels[0]))
if (!g_ascii_isxdigit (subchannels[0]))
return FALSE;
/* Get the first channel */
while (*p && (*p != ',')) {
if (!isxdigit (*p) && (*p != '.'))
if (!g_ascii_isxdigit (*p) && (*p != '.'))
return FALSE; /* Invalid chars */
if (i >= BUFSIZE)
return FALSE; /* Too long to be a subchannel */

View file

@ -18,7 +18,6 @@
*/
#include <config.h>
#include <ctype.h>
#include <glib.h>
#include <string.h>
#include <sys/types.h>
@ -886,7 +885,7 @@ ip4_process_classless_routes (GHashTable *options,
p = str;
while (*p) {
if (!isdigit (*p) && (*p != ' ') && (*p != '.') && (*p != '/')) {
if (!g_ascii_isdigit (*p) && (*p != ' ') && (*p != '.') && (*p != '/')) {
nm_log_warn (LOGD_DHCP4, "ignoring invalid classless static routes '%s'", str);
return FALSE;
}

View file

@ -22,7 +22,6 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <string.h>
#include <ctype.h>
#include "nm-dhcp-dhclient-utils.h"
@ -108,7 +107,7 @@ nm_dhcp_dhclient_create_config (const char *interface,
break;
}
if (!isalnum ((*aiter)[0]))
if (!g_ascii_isalnum ((*aiter)[0]))
continue;
if ((*aiter)[strlen (*aiter) - 1] == ';') {
@ -147,7 +146,7 @@ nm_dhcp_dhclient_create_config (const char *interface,
const char *p = tmp;
while (*p) {
if (!isxdigit (*p) && (*p != ':')) {
if (!g_ascii_isxdigit (*p) && (*p != ':')) {
is_octets = FALSE;
break;
}

View file

@ -32,7 +32,6 @@
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <config.h>

View file

@ -23,7 +23,6 @@
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <ctype.h>
#include <arpa/inet.h>
#include <glib.h>
@ -107,7 +106,7 @@ hostname_thread_worker (gpointer data)
nm_log_dbg (LOGD_DNS, "(%p) address reverse-lookup returned hostname '%s'",
ht, ht->hostname);
for (i = 0; i < strlen (ht->hostname); i++)
ht->hostname[i] = tolower (ht->hostname[i]);
ht->hostname[i] = g_ascii_tolower (ht->hostname[i]);
} else {
nm_log_dbg (LOGD_DNS, "(%p) address reverse-lookup failed: (%d) %s",
ht, ht->ret, gai_strerror (ht->ret));

View file

@ -24,7 +24,6 @@
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <ctype.h>
#include "nm-policy.h"
#include "NetworkManagerUtils.h"
@ -345,7 +344,7 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
if (dhcp_hostname && strlen (dhcp_hostname)) {
/* Sanity check; strip leading spaces */
while (*p) {
if (!isblank (*p++)) {
if (!g_ascii_isspace (*p++)) {
_set_hostname (policy, p-1, "from DHCPv4");
return;
}
@ -364,7 +363,7 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
if (dhcp_hostname && strlen (dhcp_hostname)) {
/* Sanity check; strip leading spaces */
while (*p) {
if (!isblank (*p++)) {
if (!g_ascii_isspace (*p++)) {
_set_hostname (policy, p-1, "from DHCPv6");
return;
}

View file

@ -40,7 +40,6 @@
#include <resolv.h>
#include <netdb.h>
#include <glib.h>
#include <ctype.h>
#include <linux/if.h>
#include <linux/sockios.h>
#include <linux/if_bonding.h>

View file

@ -20,7 +20,6 @@
#include <config.h>
#include <string.h>
#include <ctype.h>
#include <pwd.h>
#include <glib.h>
@ -166,7 +165,7 @@ validate_identifier (const char *identifier, GError **error)
/* FIXME: do complete validation here */
while (p && *p) {
if (!isalnum (*p) && (*p != '_') && (*p != '-') && (*p != '.')) {
if (!g_ascii_isalnum (*p) && (*p != '_') && (*p != '-') && (*p != '.')) {
g_set_error (error,
NM_AGENT_MANAGER_ERROR,
NM_AGENT_MANAGER_ERROR_INVALID_IDENTIFIER,

View file

@ -27,7 +27,6 @@
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <gmodule.h>
#include <net/if_arp.h>
#include <pwd.h>
@ -596,7 +595,7 @@ load_plugins (NMSettings *self, const char **plugins, GError **error)
GObject * (*factory_func) (const char *);
/* strip leading spaces */
while (isblank (*pname))
while (g_ascii_isspace (*pname))
pname++;
/* ifcfg-fedora was renamed ifcfg-rh; handle old configs here */

View file

@ -25,7 +25,6 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <ctype.h>
#include <sys/inotify.h>
#include <errno.h>
#include <sys/ioctl.h>
@ -1731,7 +1730,7 @@ add_one_wep_key (shvarFile *ifcfg,
char *p = value + 2;
while (*p) {
if (!isascii ((int) (*p))) {
if (!g_ascii_isprint ((int) (*p))) {
g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
"Invalid ASCII WEP key.");
goto out;
@ -2029,7 +2028,7 @@ parse_wpa_psk (shvarFile *ifcfg,
if (!quoted && (strlen (psk) == 64)) {
/* Verify the hex PSK; 64 digits */
while (*p) {
if (!isxdigit (*p++)) {
if (!g_ascii_isxdigit (*p++)) {
g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
"Invalid WPA_PSK (contains non-hexadecimal characters)");
goto out;
@ -3010,7 +3009,7 @@ make_wireless_setting (shvarFile *ifcfg,
p = value + 2;
while (*p) {
if (!isxdigit (*p)) {
if (!g_ascii_isxdigit (*p)) {
g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
"Invalid SSID '%s' character (looks like hex SSID but '%c' isn't a hex digit)",
value, *p);
@ -3281,7 +3280,7 @@ make_wired_setting (shvarFile *ifcfg,
/* basic sanity checks */
while (*p) {
if (!isxdigit (*p) && (*p != ',') && (*p != '.')) {
if (!g_ascii_isxdigit (*p) && (*p != ',') && (*p != '.')) {
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: invalid SUBCHANNELS '%s'", value);
success = FALSE;
break;

View file

@ -18,7 +18,6 @@
* Copyright (C) 2009 - 2012 Red Hat, Inc.
*/
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
@ -845,7 +844,7 @@ write_wireless_setting (NMConnection *connection,
* hex notation of the SSID instead.
*/
for (i = 0; i < ssid->len; i++) {
if (!isprint (ssid->data[i])) {
if (!g_ascii_isprint (ssid->data[i])) {
hex_ssid = TRUE;
break;
}

View file

@ -26,7 +26,6 @@
#include <stdlib.h>
#include <netinet/ether.h>
#include <errno.h>
#include <ctype.h>
#include <glib/gi18n.h>
#include <nm-setting-connection.h>
@ -2291,7 +2290,7 @@ write_wireless_setting (NMConnection *connection,
* support these characters, see bug #356337)
*/
for (i = 0; i < ssid->len; i++) {
if (!isalnum (ssid->data[i])) {
if (!g_ascii_isalnum (ssid->data[i])) {
hex_ssid = TRUE;
break;
}
@ -2953,7 +2952,7 @@ get_wireless_name (NMConnection * connection)
}
for (i = 0; i < ssid->len; i++) {
if (!isprint (ssid->data[i])) {
if (!g_ascii_isprint (ssid->data[i])) {
hex_ssid = TRUE;
break;
}

View file

@ -22,7 +22,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <nm-utils.h>
#include <nm-system-config-interface.h>
@ -67,7 +66,7 @@ is_hex (const char *value)
if (!p)
return FALSE;
while (*p) {
if (!isxdigit (*p++))
if (!g_ascii_isxdigit (*p++))
return FALSE;
}
return TRUE;
@ -79,7 +78,7 @@ is_ascii (const char *value)
const char *p = value;
while (*p) {
if (!isascii (*p++))
if (!g_ascii_isprint (*p++))
return FALSE;
}
return TRUE;
@ -462,7 +461,7 @@ create_ip4_block (gchar * ip)
iblock->ip = tmp_ip4_addr.s_addr;
prefix = ip_mask[1];
i = 0;
while (i < length && isdigit (prefix[i]))
while (i < length && g_ascii_isdigit (prefix[i]))
i++;
prefix[i] = '\0';
iblock->netmask = nm_utils_ip4_prefix_to_netmask ((guint32)

View file

@ -25,7 +25,6 @@
#include <arpa/inet.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <nm-connection.h>
#include <NetworkManager.h>
@ -446,7 +445,7 @@ ifupdown_ip4_add_dns (NMSettingIP4Config *s_ip4, const char *dns)
list = g_strsplit_set (dns, " \t", -1);
for (iter = list; iter && *iter; iter++) {
g_strstrip (*iter);
if (isblank (*iter[0]))
if (g_ascii_isspace (*iter[0]))
continue;
if (!inet_pton (AF_INET, *iter, &addr)) {
PLUGIN_WARN ("SCPlugin-Ifupdown",
@ -552,7 +551,7 @@ update_ip4_setting_from_if_block(NMConnection *connection,
list = g_strsplit_set (search_v, " \t", -1);
for (iter = list; iter && *iter; iter++) {
g_strstrip (*iter);
if (isblank (*iter[0]))
if (g_ascii_isspace (*iter[0]))
continue;
if (!nm_setting_ip4_config_add_dns_search (s_ip4, *iter)) {
PLUGIN_WARN ("SCPlugin-Ifupdown",
@ -585,7 +584,7 @@ ifupdown_ip6_add_dns (NMSettingIP6Config *s_ip6, const char *dns)
list = g_strsplit_set (dns, " \t", -1);
for (iter = list; iter && *iter; iter++) {
g_strstrip (*iter);
if (isblank (*iter[0]))
if (g_ascii_isspace (*iter[0]))
continue;
if (!inet_pton (AF_INET6, *iter, &addr)) {
PLUGIN_WARN ("SCPlugin-Ifupdown",

View file

@ -39,7 +39,6 @@
#include <netinet/ether.h>
#include <linux/if_infiniband.h>
#include <string.h>
#include <ctype.h>
#include "nm-dbus-glib-types.h"
#include "nm-system-config-interface.h"

View file

@ -41,7 +41,6 @@
#include <string.h>
#include <arpa/inet.h>
#include <netinet/ether.h>
#include <ctype.h>
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
@ -500,7 +499,7 @@ ssid_writer (GKeyFile *file,
*/
for (i = 0; i < array->len; i++) {
char c = array->data[i] & 0xFF;
if (!isprint (c)) {
if (!g_ascii_isprint (c)) {
new_format = FALSE;
break;
}

View file

@ -32,7 +32,6 @@
#include <config.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>