From f11a3ee4ffc0c81cd1b27af469d8dad6d48fbf49 Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Sun, 24 Nov 2013 23:51:28 +0000 Subject: most obvious unsigned char casts for ctype ok jca krw ingo --- src/lib/libc/net/base64.c | 14 +++++++------- src/lib/libc/net/ethers.c | 10 ++++++---- src/lib/libc/net/inet_addr.c | 16 ++++++++++------ src/lib/libc/net/ruserok.c | 7 ++++--- 4 files changed, 27 insertions(+), 20 deletions(-) (limited to 'src/lib/libc/net') diff --git a/src/lib/libc/net/base64.c b/src/lib/libc/net/base64.c index d432c48d5c..78ef449a75 100644 --- a/src/lib/libc/net/base64.c +++ b/src/lib/libc/net/base64.c @@ -1,4 +1,4 @@ -/* $OpenBSD: base64.c,v 1.5 2006/10/21 09:55:03 otto Exp $ */ +/* $OpenBSD: base64.c,v 1.6 2013/11/24 23:51:28 deraadt Exp $ */ /* * Copyright (c) 1996 by Internet Software Consortium. @@ -199,7 +199,7 @@ b64_pton(src, target, targsize) state = 0; tarindex = 0; - while ((ch = *src++) != '\0') { + while ((ch = (unsigned char)*src++) != '\0') { if (isspace(ch)) /* Skip whitespace anywhere. */ continue; @@ -258,8 +258,8 @@ b64_pton(src, target, targsize) * on a byte boundary, and/or with erroneous trailing characters. */ - if (ch == Pad64) { /* We got a pad char. */ - ch = *src++; /* Skip it, get next. */ + if (ch == Pad64) { /* We got a pad char. */ + ch = (unsigned char)*src++; /* Skip it, get next. */ switch (state) { case 0: /* Invalid = in first position */ case 1: /* Invalid = in second position */ @@ -267,13 +267,13 @@ b64_pton(src, target, targsize) case 2: /* Valid, means one byte of info */ /* Skip any number of spaces. */ - for (; ch != '\0'; ch = *src++) + for (; ch != '\0'; ch = (unsigned char)*src++) if (!isspace(ch)) break; /* Make sure there is another trailing = sign. */ if (ch != Pad64) return (-1); - ch = *src++; /* Skip the = */ + ch = (unsigned char)*src++; /* Skip the = */ /* Fall through to "single trailing =" case. */ /* FALLTHROUGH */ @@ -282,7 +282,7 @@ b64_pton(src, target, targsize) * We know this char is an =. Is there anything but * whitespace after it? */ - for (; ch != '\0'; ch = *src++) + for (; ch != '\0'; ch = (unsigned char)*src++) if (!isspace(ch)) return (-1); diff --git a/src/lib/libc/net/ethers.c b/src/lib/libc/net/ethers.c index d4243ff1da..af31bb8e60 100644 --- a/src/lib/libc/net/ethers.c +++ b/src/lib/libc/net/ethers.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ethers.c,v 1.20 2005/08/06 20:30:03 espie Exp $ */ +/* $OpenBSD: ethers.c,v 1.21 2013/11/24 23:51:28 deraadt Exp $ */ /* * Copyright (c) 1998 Todd C. Miller @@ -64,7 +64,7 @@ _ether_aton(const char *s, struct ether_addr *e) long l; char *pp; - while (isspace(*s)) + while (isspace((unsigned char)*s)) s++; /* expect 6 hex octets separated by ':' or space/NUL if last octet */ @@ -72,7 +72,9 @@ _ether_aton(const char *s, struct ether_addr *e) l = strtol(s, &pp, 16); if (pp == s || l > 0xFF || l < 0) return (NULL); - if (!(*pp == ':' || (i == 5 && (isspace(*pp) || *pp == '\0')))) + if (!(*pp == ':' || + (i == 5 && (isspace((unsigned char)*pp) || + *pp == '\0')))) return (NULL); e->ether_addr_octet[i] = (u_char)l; s = pp + 1; @@ -216,7 +218,7 @@ ether_line(const char *line, struct ether_addr *e, char *hostname) goto bad; /* Now get the hostname */ - while (isspace(*p)) + while (isspace((unsigned char)*p)) p++; if (*p == '\0') goto bad; diff --git a/src/lib/libc/net/inet_addr.c b/src/lib/libc/net/inet_addr.c index c962a03382..18762ab522 100644 --- a/src/lib/libc/net/inet_addr.c +++ b/src/lib/libc/net/inet_addr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet_addr.c,v 1.9 2005/08/06 20:30:03 espie Exp $ */ +/* $OpenBSD: inet_addr.c,v 1.10 2013/11/24 23:51:28 deraadt Exp $ */ /* * ++Copyright++ 1983, 1990, 1993 @@ -94,7 +94,7 @@ inet_aton(const char *cp, struct in_addr *addr) * Values are specified as for C: * 0x=hex, 0=octal, isdigit=decimal. */ - if (!isdigit(c)) + if (!isdigit((unsigned char)c)) return (0); val = 0; base = 10; if (c == '0') { @@ -105,12 +105,15 @@ inet_aton(const char *cp, struct in_addr *addr) base = 8; } for (;;) { - if (isascii(c) && isdigit(c)) { + if (isascii((unsigned char)c) && + isdigit((unsigned char)c)) { val = (val * base) + (c - '0'); c = *++cp; - } else if (base == 16 && isascii(c) && isxdigit(c)) { + } else if (base == 16 && + isascii((unsigned char)c) && + isxdigit((unsigned char)c)) { val = (val << 4) | - (c + 10 - (islower(c) ? 'a' : 'A')); + (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); c = *++cp; } else break; @@ -132,7 +135,8 @@ inet_aton(const char *cp, struct in_addr *addr) /* * Check for trailing characters. */ - if (c != '\0' && (!isascii(c) || !isspace(c))) + if (c != '\0' && + (!isascii((unsigned char)c) || !isspace((unsigned char)c))) return (0); /* * Concoct the address according to diff --git a/src/lib/libc/net/ruserok.c b/src/lib/libc/net/ruserok.c index 46fba4beb2..21646c156b 100644 --- a/src/lib/libc/net/ruserok.c +++ b/src/lib/libc/net/ruserok.c @@ -214,9 +214,10 @@ __ivaliduser_sa(FILE *hostf, struct sockaddr *raddr, socklen_t salen, if (*p == '#') continue; while (p < buf + buflen && *p != '\n' && *p != ' ' && *p != '\t') { - if (!isprint(*p)) + if (!isprint((unsigned char)*p)) goto bail; - *p = isupper(*p) ? tolower(*p) : *p; + *p = isupper((unsigned char)*p) ? + tolower((unsigned char)*p) : *p; p++; } if (p >= buf + buflen) @@ -230,7 +231,7 @@ __ivaliduser_sa(FILE *hostf, struct sockaddr *raddr, socklen_t salen, user = p; while (p < buf + buflen && *p != '\n' && *p != ' ' && *p != '\t') { - if (!isprint(*p)) + if (!isprint((unsigned char)*p)) goto bail; p++; } -- cgit v1.2.3-55-g6feb