Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/flashctl flashctl: fix error handling of integer ar...



details:   https://anonhg.NetBSD.org/src/rev/126d66f6073a
branches:  trunk
changeset: 372966:126d66f6073a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 08 15:37:56 2023 +0000

description:
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.

diffstat:

 usr.sbin/flashctl/flashctl.c |  8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diffs (25 lines):

diff -r 30544e45da7c -r 126d66f6073a usr.sbin/flashctl/flashctl.c
--- a/usr.sbin/flashctl/flashctl.c      Sun Jan 08 15:22:33 2023 +0000
+++ b/usr.sbin/flashctl/flashctl.c      Sun Jan 08 15:37:56 2023 +0000
@@ -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 @@
        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);
        }



Home | Main Index | Thread Index | Old Index