From 149a3464ef35fbaa98c57e2775a7a4ab20c2ee75 Mon Sep 17 00:00:00 2001
From: Steve Grubb <ausearch.1@gmail.com>
Date: Sun, 5 Nov 2023 14:24:49 -0500
Subject: [PATCH] fix the use of isdigit everywhere

Reference:https://github.com/linux-audit/audit-userspace/commit/149a3464ef35fbaa98c57e2775a7a4ab20c2ee75
Conflict:NA

---
 audisp/plugins/af_unix/audisp-af_unix.c       |  2 +-
 audisp/plugins/ids/ids_config.c               |  2 +-
 audisp/plugins/remote/remote-config.c         |  2 +-
 audisp/plugins/zos-remote/zos-remote-config.c |  6 ++--
 auparse/auditd-config.c                       |  2 +-
 auparse/interpret.c                           |  6 ++--
 src/auditctl.c                                |  6 ++--
 src/aureport-options.c                        |  4 +--
 src/aureport-output.c                         |  2 +-
 src/ausearch-options.c                        | 36 +++++++++----------
 src/ausearch-parse.c                          |  2 +-
 tools/ausyscall/ausyscall.c                   |  4 +--
 12 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/audisp/plugins/af_unix/audisp-af_unix.c b/audisp/plugins/af_unix/audisp-af_unix.c
index ffcc7603..ffbf2ac0 100644
--- a/audisp/plugins/af_unix/audisp-af_unix.c
+++ b/audisp/plugins/af_unix/audisp-af_unix.c
@@ -126,7 +126,7 @@ int setup_socket(int argc, char *argv[])
 	} else {
 		int i;
 		for (i=1; i < 3; i++) {
-			if (isdigit(argv[i][0])) {
+			if (isdigit((unsigned char)argv[i][0])) {
 				errno = 0;
 				mode = strtoul(argv[i], NULL, 8);
 				if (errno) {
diff --git a/audisp/plugins/ids/ids_config.c b/audisp/plugins/ids/ids_config.c
index 4da5ca93..f773794a 100644
--- a/audisp/plugins/ids/ids_config.c
+++ b/audisp/plugins/ids/ids_config.c
@@ -345,7 +345,7 @@ static int unsigned_int_parser(struct nv_pair *nv, int line, unsigned int *val)
 
 	/* check that all chars are numbers */
 	for (i=0; ptr[i]; i++) {
-		if (!isdigit(ptr[i])) {
+		if (!isdigit((unsigned char)ptr[i])) {
 			syslog(LOG_ERR,
 				"Value %s should only be numbers - line %d",
 				nv->value, line);
diff --git a/audisp/plugins/remote/remote-config.c b/audisp/plugins/remote/remote-config.c
index 02b51337..8de7b27f 100644
--- a/audisp/plugins/remote/remote-config.c
+++ b/audisp/plugins/remote/remote-config.c
@@ -484,7 +484,7 @@ static int parse_uint (const struct nv_pair *nv, int line, unsigned int *valp,
 
 	/* check that all chars are numbers */
 	for (i=0; ptr[i]; i++) {
-		if (!isdigit(ptr[i])) {
+		if (!isdigit((unsigned char)ptr[i])) {
 			syslog(LOG_ERR,
 				"Value %s should only be numbers - line %d",
 				nv->value, line);
diff --git a/audisp/plugins/zos-remote/zos-remote-config.c b/audisp/plugins/zos-remote/zos-remote-config.c
index b92dc778..2f7e42f5 100644
--- a/audisp/plugins/zos-remote/zos-remote-config.c
+++ b/audisp/plugins/zos-remote/zos-remote-config.c
@@ -301,7 +301,7 @@ static int port_parser(struct nv_pair *nv, int line, plugin_conf_t * c)
 
         /* check that all chars are numbers */
         for (i = 0; ptr[i]; i++) {
-                if (!isdigit(ptr[i])) {
+                if (!isdigit((unsigned char)ptr[i])) {
                         log_err("Value %s should only be numbers - line %d", nv->value, line);
                         return 1;
                 }
@@ -327,7 +327,7 @@ static int timeout_parser(struct nv_pair *nv, int line, plugin_conf_t * c)
 
         /* check that all chars are numbers */
         for (i = 0; ptr[i]; i++) {
-                if (!isdigit(ptr[i])) {
+                if (!isdigit((unsigned char)ptr[i])) {
                         log_err("Value %s should only be numbers - line %d", nv->value, line);
                         return 1;
                 }
@@ -376,7 +376,7 @@ static int q_depth_parser(struct nv_pair *nv, int line, plugin_conf_t * c)
 
         /* check that all chars are numbers */
         for (i = 0; ptr[i]; i++) {
-                if (!isdigit(ptr[i])) {
+                if (!isdigit((unsigned char)ptr[i])) {
                         log_err("Value %s should only be numbers - line %d", nv->value, line);
                         return 1;
                 }
diff --git a/auparse/auditd-config.c b/auparse/auditd-config.c
index 9a6a6a71..6e5c86a8 100644
--- a/auparse/auditd-config.c
+++ b/auparse/auditd-config.c
@@ -340,7 +340,7 @@ static int eoe_timeout_parser(auparse_state_t *au, const char *val, int line,
 
 	/* check that all chars are numbers */
 	for (i=0; ptr[i]; i++) {
-		if (!isdigit(ptr[i])) {
+		if (!isdigit((unsigned char)ptr[i])) {
 			audit_msg(au, LOG_ERR,
 				"Value %s should only be numbers - line %d",
 				val, line);
diff --git a/auparse/interpret.c b/auparse/interpret.c
index f13723b6..77c96468 100644
--- a/auparse/interpret.c
+++ b/auparse/interpret.c
@@ -325,7 +325,7 @@ static void key_escape(const char *orig, char *dest, auparse_esc_t escape_mode)
 static int is_int_string(const char *str)
 {
 	while (*str) {
-		if (!isdigit(*str))
+		if (!isdigit((unsigned char)*str))
 			return 0;
 		str++;
 	}
@@ -1485,7 +1485,7 @@ static const char *print_success(const char *val)
 {
         int res;
 
-	if (isdigit(*val)) {
+	if (isdigit((unsigned char)*val)) {
 	        errno = 0;
 		res = strtoul(val, NULL, 10);
 	        if (errno) {
@@ -2319,7 +2319,7 @@ static const char *print_fanotify(const char *val)
 {
         int res;
 
-	if (isdigit(*val)) {
+	if (isdigit((unsigned char)*val)) {
 	        errno = 0;
 		res = strtoul(val, NULL, 10);
 	        if (errno) {
diff --git a/src/auditctl.c b/src/auditctl.c
index ccd62bc3..e1ca0f83 100644
--- a/src/auditctl.c
+++ b/src/auditctl.c
@@ -680,7 +680,7 @@ static int setopt(int count, int lineno, char *vars[])
 		}
 		break;
         case 'r':
-		if (optarg && isdigit(optarg[0])) { 
+		if (optarg && isdigit((unsigned char)optarg[0])) {
 			uint32_t rate;
 			errno = 0;
 			rate = strtoul(optarg,NULL,0);
@@ -699,7 +699,7 @@ static int setopt(int count, int lineno, char *vars[])
 		}
 		break;
         case 'b':
-		if (optarg && isdigit(optarg[0])) {
+		if (optarg && isdigit((unsigned char)optarg[0])) {
 			uint32_t limit;
 			errno = 0;
 			limit = strtoul(optarg,NULL,0);
@@ -1134,7 +1134,7 @@ process_keys:
 	case 2:
 #if HAVE_DECL_AUDIT_VERSION_BACKLOG_WAIT_TIME == 1 || \
     HAVE_DECL_AUDIT_STATUS_BACKLOG_WAIT_TIME == 1
-		if (optarg && isdigit(optarg[0])) {
+		if (optarg && isdigit((unsigned char)optarg[0])) {
 			uint32_t bwt;
 			errno = 0;
 			bwt = strtoul(optarg,NULL,0);
diff --git a/src/aureport-options.c b/src/aureport-options.c
index 203c3880..7480c8a9 100644
--- a/src/aureport-options.c
+++ b/src/aureport-options.c
@@ -385,7 +385,7 @@ int check_params(int count, char *vars[])
 //				} else {
 //					UNIMPLEMENTED;
 //					set_detail(D_SPECIFIC);
-//					if (isdigit(optarg[0])) {
+//					if (isdigit((unsigned char)optarg[0])) {
 //						errno = 0;
 //						event_id = strtoul(optarg,
 //							NULL, 10);
@@ -764,7 +764,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				arg_eoe_timeout = (time_t)strtoul(optarg, NULL, 10);
 				if (errno || arg_eoe_timeout == 0) {
diff --git a/src/aureport-output.c b/src/aureport-output.c
index a635d536..27a2ce25 100644
--- a/src/aureport-output.c
+++ b/src/aureport-output.c
@@ -976,7 +976,7 @@ static void do_user_summary_output(slist *sptr)
 		long uid;
 		char name[64];
 
-		if (sn->str[0] == '-' || isdigit(sn->str[0])) {
+		if (sn->str[0] == '-' || isdigit((unsigned char)sn->str[0])) {
 			uid = strtol(sn->str, NULL, 10);
 			printf("%u  ", sn->hits);
 			safe_print_string(aulookup_uid(uid, name,
diff --git a/src/ausearch-options.c b/src/ausearch-options.c
index 53d0db64..1c653648 100644
--- a/src/ausearch-options.c
+++ b/src/ausearch-options.c
@@ -253,7 +253,7 @@ static int convert_str_to_msg(const char *optarg)
 {
 	int tmp, retval = 0;
 
-	if (isdigit(optarg[0])) {
+	if (isdigit((unsigned char)optarg[0])) {
 		errno = 0;
 		tmp = strtoul(optarg, NULL, 10);
 		if (errno) {
@@ -335,7 +335,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_id = strtoul(optarg, NULL, 10);
 				if (errno) {
@@ -357,7 +357,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				arg_eoe_timeout = (time_t)strtoul(optarg, NULL, 10);
 				if (errno || arg_eoe_timeout == 0) {
@@ -463,7 +463,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_gid = strtoul(optarg,NULL,10);
 				if (errno) {
@@ -497,7 +497,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_egid = strtoul(optarg,NULL,10);
 				if (errno) {
@@ -529,7 +529,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_gid = strtoul(optarg,NULL,10);
 				if (errno) {
@@ -655,7 +655,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_ppid = strtol(optarg,NULL,10);
 				if (errno)
@@ -676,7 +676,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_pid = strtol(optarg,NULL,10);
 				if (errno)
@@ -794,7 +794,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_syscall = (int)strtoul(optarg, NULL, 10);
 				if (errno) {
@@ -893,7 +893,7 @@ int check_params(int count, char *vars[])
 			}
 			{
 			size_t len = strlen(optarg);
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				unsigned long optval = strtoul(optarg,NULL,10);
 				if (errno || optval >= (1ul << 32))
@@ -901,7 +901,7 @@ int check_params(int count, char *vars[])
 				event_session_id = optval;
 				c++;
                         } else if (len >= 2 && *(optarg)=='-' &&
-                                                (isdigit(optarg[1]))) {
+                                                (isdigit((unsigned char)optarg[1]))) {
 				errno = 0;
 				long optval = strtol(optarg, NULL, 0);
 				if (errno || optval < INT_MIN || optval > INT_MAX) {
@@ -933,7 +933,7 @@ int check_params(int count, char *vars[])
 			}
 			{
 			size_t len = strlen(optarg);
-                        if (isdigit(optarg[0])) {
+                        if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
                                 event_exit = strtoll(optarg, NULL, 0);
 				if (errno) {
@@ -942,7 +942,7 @@ int check_params(int count, char *vars[])
 						optarg);
 				}
                         } else if (len >= 2 && *(optarg)=='-' &&
-                                                (isdigit(optarg[1]))) {
+                                                (isdigit((unsigned char)optarg[1]))) {
 				errno = 0;
                                 event_exit = strtoll(optarg, NULL, 0);
 				if (errno) {
@@ -1074,7 +1074,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_uid = strtoul(optarg,NULL,10);
 				if (errno) {
@@ -1107,7 +1107,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_euid = strtoul(optarg,NULL,10);
 				if (errno) {
@@ -1140,7 +1140,7 @@ int check_params(int count, char *vars[])
 				retval = -1;
 				break;
 			}
-			if (isdigit(optarg[0])) {
+			if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_uid = strtoul(optarg,NULL,10);
 				if (errno) {
@@ -1184,7 +1184,7 @@ int check_params(int count, char *vars[])
 			}
 			{
 			size_t len = strlen(optarg);
-                        if (isdigit(optarg[0])) {
+                        if (isdigit((unsigned char)optarg[0])) {
 				errno = 0;
 				event_loginuid = strtoul(optarg,NULL,10);
 				if (errno) {
@@ -1194,7 +1194,7 @@ int check_params(int count, char *vars[])
                                         retval = -1;
 				}
                         } else if (len >= 2 && *(optarg)=='-' &&
-                                                (isdigit(optarg[1]))) {
+                                                (isdigit((unsigned char)optarg[1]))) {
 				errno = 0;
                                 event_loginuid = strtol(optarg, NULL, 0);
 				if (errno) {
diff --git a/src/ausearch-parse.c b/src/ausearch-parse.c
index e6868c6e..1a5b047f 100644
--- a/src/ausearch-parse.c
+++ b/src/ausearch-parse.c
@@ -1128,7 +1128,7 @@ try_again:
 				return 25;
 			ptr = str + 4;
 			term = ptr;
-			while (isdigit(*term))
+			while (isdigit((unsigned char)*term))
 				term++;
 			if (term == ptr)
 				return 14;
diff --git a/tools/ausyscall/ausyscall.c b/tools/ausyscall/ausyscall.c
index bf751f17..489b1095 100644
--- a/tools/ausyscall/ausyscall.c
+++ b/tools/ausyscall/ausyscall.c
@@ -47,9 +47,9 @@ int main(int argc, char *argv[])
 		usage();
 	} else if (argc < 2)
 		usage();
- 
+
 	for (i=1; i<argc; i++) {
-		if (isdigit(argv[i][0])) {
+		if (isdigit((unsigned char)argv[i][0])) {
 			if (syscall_num != -1) {
 				fputs("Two syscall numbers not allowed\n",
 					stderr);
-- 
2.33.0

