Module Name:    src
Committed By:   rillig
Date:           Sun Jan  8 15:37:56 UTC 2023

Modified Files:
        src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: fix error handling of integer arguments

Previously, flashctl accepted the command 'erase 0x 0x' as valid, even
though the numbers are not valid hex numbers.

Pointed out by lint, which complained about the wrong type conversion
for tolower, isxdigit and isdigit.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.4 src/usr.sbin/flashctl/flashctl.c:1.5
--- src/usr.sbin/flashctl/flashctl.c:1.4	Tue May 24 13:01:53 2011
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 15:37:56 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.4 2011/05/24 13:01:53 joerg Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.5 2023/01/08 15:37:56 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -229,12 +229,12 @@ to_intmax(intmax_t *num, const char *str
 	char *endptr;
 
 	errno = 0;
-	if (str[0] == '0' && tolower((int )str[1]) == 'x') {
-		if (!isxdigit((int )str[0]))
+	if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
+		if (!isxdigit((unsigned char)str[2]))
 			return EINVAL;
 		*num = strtoimax(str, &endptr, 16);
 	} else {
-		if (!isdigit((int )str[0]))
+		if (!isdigit((unsigned char)str[0]))
 			return EINVAL;
 		*num = strtoimax(str, &endptr, 10);
 	}

Reply via email to