]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (script) fix possible partno overflow
authorKarel Zak <kzak@redhat.com>
Fri, 14 Aug 2020 09:13:50 +0000 (11:13 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 10:51:28 +0000 (11:51 +0100)
Addresses: https://oss-fuzz.com/testcase-detail/5740890480705536
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/script.c

index ea16f139267dd6ab1a5cad37fdca4406e4a39805..789581776525d5ca878a4389193f7c3b3907993e 100644 (file)
@@ -955,7 +955,7 @@ static int next_string(char **s, char **str)
 
 static int partno_from_devname(char *s)
 {
-       int pno;
+       intmax_t num;
        size_t sz;
        char *end, *p;
 
@@ -971,10 +971,15 @@ static int partno_from_devname(char *s)
                return -1;
        end = NULL;
        errno = 0;
-       pno = strtol(p, &end, 10);
+       num = strtol(p, &end, 10);
        if (errno || !end || p == end)
                return -1;
-       return pno - 1;
+
+       if (num < INT32_MIN || num > INT32_MAX) {
+               errno = ERANGE;
+               return -1;
+       }
+       return num - 1;
 }
 
 #define FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS \