]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (script) fix partno_from_devname()
authorKarel Zak <kzak@redhat.com>
Mon, 27 Apr 2020 09:15:00 +0000 (11:15 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 27 Apr 2020 09:15:00 +0000 (11:15 +0200)
Addresses: https://github.com/karelzak/util-linux/issues/1015
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/script.c

index cc53c3b7db5ca8cedfe090defcaa3579c127af6e..8af2e54cd26fb4656cad359defb5e7cfe0383189 100644 (file)
@@ -953,12 +953,17 @@ static int partno_from_devname(char *s)
        size_t sz;
        char *end, *p;
 
+       if (!s || !*s)
+               return -1;
+
        sz = rtrim_whitespace((unsigned char *)s);
-       p = s + sz - 1;
+       end = p = s + sz;
 
        while (p > s && isdigit(*(p - 1)))
                p--;
-
+       if (p == end)
+               return -1;
+       end = NULL;
        errno = 0;
        pno = strtol(p, &end, 10);
        if (errno || !end || p == end)