]> 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, 14 Aug 2020 09:13:50 +0000 (11:13 +0200)
Addresses: https://oss-fuzz.com/testcase-detail/5740890480705536
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/script.c

index 74ff43b739145f981494b4c4b8edd301486c5669..37a5a3edc3f6463774a0ceb911d1856383c0c185 100644 (file)
@@ -959,7 +959,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;
 
@@ -975,10 +975,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 \