]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use isdigit instead of checking character range
authorMatthijs Mekking <matthijs@isc.org>
Wed, 14 Apr 2021 07:19:20 +0000 (09:19 +0200)
committerMatthijs Mekking <matthijs@isc.org>
Wed, 5 May 2021 16:23:53 +0000 (18:23 +0200)
When looking for key files, we could use isdigit rather than checking
if the character is within the range [0-9].

Use (unsigned char) cast to ensure the value is representable in the
unsigned char type (as suggested by the isdigit manpage).

Change " & 0xff" occurrences to the recommended (unsigned char) type
cast.

(cherry picked from commit 1998ad6c776a9c17c27788b17765dee90d9e25df)

12 files changed:
bin/named/unix/os.c
lib/bind9/check.c
lib/dns/dnssec.c
lib/dns/name.c
lib/dns/rcode.c
lib/dns/rdata/generic/x25_19.c
lib/dns/rdata/in_1/atma_34.c
lib/isc/tm.c
lib/isc/unix/dir.c
lib/isc/win32/dir.c
lib/isc/win32/file.c
lib/ns/query.c

index f28aade36f50a04f3271c8ed5910b3d731034963..02f5cb15dd00c248c6014e0c2cf57f748718e137 100644 (file)
@@ -379,7 +379,7 @@ all_digits(const char *s) {
                return (false);
        }
        while (*s != '\0') {
-               if (!isdigit((*s) & 0xff)) {
+               if (!isdigit((unsigned char)(*s))) {
                        return (false);
                }
                s++;
index c0c9d02c0e7f98c45845d6e3de2d81ea953de715..72b4251c5db9e8f7e98b9d1cb734d464d2f92186 100644 (file)
@@ -11,6 +11,7 @@
 
 /*! \file */
 
+#include <ctype.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stdlib.h>
index f2a107b5fd05c6e69c35b4764a298f1067ecb7d9..acba420e1fa1688096b35ccf927e4d932e1bd8bf 100644 (file)
@@ -11,6 +11,7 @@
 
 /*! \file */
 
+#include <ctype.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stdlib.h>
@@ -1433,8 +1434,7 @@ dns_dnssec_findmatchingkeys(const dns_name_t *origin, const char *directory,
 
                alg = 0;
                for (i = len + 1 + 1; i < dir.entry.length; i++) {
-                       if (dir.entry.name[i] < '0' || dir.entry.name[i] > '9')
-                       {
+                       if (!isdigit((unsigned char)dir.entry.name[i])) {
                                break;
                        }
                        alg *= 10;
@@ -1452,15 +1452,8 @@ dns_dnssec_findmatchingkeys(const dns_name_t *origin, const char *directory,
                }
 
                for (i++; i < dir.entry.length; i++) {
-                       if (dir.entry.name[i] < '0' || dir.entry.name[i] > '9')
-                       {
+                       if (!isdigit((unsigned char)dir.entry.name[i])) {
                                break;
-
-                               /*
-                                * Did we not read exactly 5 more digits?
-                                * Did we overflow?
-                                * Did we correctly terminate?
-                                */
                        }
                }
 
index 441d06ce377196c52f79631b68c90d4df92d1ab2..35000bf99ee827f151f587c5aab4cbd262251402 100644 (file)
@@ -1204,7 +1204,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
                        POST(state);
                /* FALLTHROUGH */
                case ft_escape:
-                       if (!isdigit(c & 0xff)) {
+                       if (!isdigit((unsigned char)c)) {
                                if (count >= 63) {
                                        return (DNS_R_LABELTOOLONG);
                                }
@@ -1224,7 +1224,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
                        state = ft_escdecimal;
                /* FALLTHROUGH */
                case ft_escdecimal:
-                       if (!isdigit(c & 0xff)) {
+                       if (!isdigit((unsigned char)c)) {
                                return (DNS_R_BADESCAPE);
                        }
                        value *= 10;
index 25819706396d96dc022843733a758bc7598ac08b..ef046b33220bda78112410af424e9095169d960a 100644 (file)
@@ -219,8 +219,8 @@ maybe_numeric(unsigned int *valuep, isc_textregion_t *source, unsigned int max,
        char buffer[NUMBERSIZE];
        int v;
 
-       if (!isdigit(source->base[0] & 0xff) || source->length > NUMBERSIZE - 1)
-       {
+       if (!isdigit((unsigned char)source->base[0]) ||
+           source->length > NUMBERSIZE - 1) {
                return (ISC_R_BADNUMBER);
        }
 
index 80ef247600e50221e4ffc9a7908f0e78f9aca480..0ba32d582f81bda87915473833c68c64c9692db3 100644 (file)
@@ -35,7 +35,8 @@ fromtext_x25(ARGS_FROMTEXT) {
                RETTOK(DNS_R_SYNTAX);
        }
        for (i = 0; i < token.value.as_textregion.length; i++) {
-               if (!isdigit(token.value.as_textregion.base[i] & 0xff)) {
+               if (!isdigit((unsigned char)token.value.as_textregion.base[i]))
+               {
                        RETTOK(ISC_R_RANGE);
                }
        }
@@ -125,7 +126,7 @@ fromstruct_x25(ARGS_FROMSTRUCT) {
        }
 
        for (i = 0; i < x25->x25_len; i++) {
-               if (!isdigit(x25->x25[i] & 0xff)) {
+               if (!isdigit((unsigned char)x25->x25[i])) {
                        return (ISC_R_RANGE);
                }
        }
index 893e8cda8209e27c2982af4670bf47657322cc09..07a9198e53b4053468157ccd324e1870bd87cb86 100644 (file)
@@ -91,7 +91,7 @@ fromtext_in_atma(ARGS_FROMTEXT) {
                                lastwasperiod = true;
                                continue;
                        }
-                       if ((sr->base[0] < '0') || (sr->base[0] > '9')) {
+                       if (!isdigit((unsigned char)sr->base[0])) {
                                RETTOK(DNS_R_SYNTAX);
                        }
                        RETERR(mem_tobuffer(target, sr->base, 1));
@@ -157,7 +157,7 @@ fromwire_in_atma(ARGS_FROMWIRE) {
        if (region.base[0] == 1) {
                unsigned int i;
                for (i = 1; i < region.length; i++) {
-                       if (region.base[i] < '0' || region.base[i] > '9') {
+                       if (!isdigit((unsigned char)region.base[i])) {
                                return (DNS_R_FORMERR);
                        }
                }
index 5309b14664e39801c4dff7565d1f4a3ad75f448d..9c0a8e36f1ec267588471658b8f16f80ee63a0c3 100644 (file)
@@ -89,7 +89,7 @@ conv_num(const char **buf, int *dest, int llim, int ulim) {
        /* The limit also determines the number of valid digits. */
        int rulim = ulim;
 
-       if (**buf < '0' || **buf > '9') {
+       if (!isdigit((unsigned char)**buf)) {
                return (0);
        }
 
index 29e4bb794e9c5ffe7db0168f9d9c028201566052..49367956fd0dfaf61576cf58cfef92713ef979c3 100644 (file)
@@ -230,7 +230,7 @@ isc_dir_createunique(char *templet) {
                 */
                p = x;
                while (*p != '\0') {
-                       if (isdigit(*p & 0xff)) {
+                       if (isdigit((unsigned char)*p)) {
                                *p = 'a';
                        } else if (*p != 'z') {
                                ++*p;
index 006f60a981ed9d9779b8bcca0dd480aa1b8811f4..cbfc0dc98e38187820800aa626a5f1dc881c7ea5 100644 (file)
@@ -273,7 +273,7 @@ isc_dir_createunique(char *templet) {
                 */
                p = x;
                while (*p != '\0') {
-                       if (isdigit(*p & 0xff)) {
+                       if (isdigit((unsigned char)*p)) {
                                *p = 'a';
                        } else if (*p != 'z') {
                                ++*p;
index 624b24d71e3f75f2aa6fc902440a23587931217e..e1d3c891411e608ddbf53feeeb62472976f06b27 100644 (file)
@@ -102,7 +102,7 @@ gettemp(char *path, bool binary, int *doopen) {
                        if (*trv == 'z') {
                                *trv++ = 'a';
                        } else {
-                               if (isdigit(*trv)) {
+                               if (isdigit((unsigned char)*trv)) {
                                        *trv = 'a';
                                } else {
                                        ++*trv;
index fc000f5799478fe8c0dec11b3804c7963dd2c4bb..7978139cc08e43e8f594b8c1fc537dd9b68fabf4 100644 (file)
@@ -11,6 +11,7 @@
 
 /*! \file */
 
+#include <ctype.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <string.h>
@@ -5287,7 +5288,7 @@ get_root_key_sentinel_id(query_ctx_t *qctx, const char *ndata) {
        int i;
 
        for (i = 0; i < 5; i++) {
-               if (ndata[i] < '0' || ndata[i] > '9') {
+               if (!isdigit((unsigned char)ndata[i])) {
                        return (false);
                }
                v *= 10;