]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: make partition types uses more robust
authorKarel Zak <kzak@redhat.com>
Thu, 10 Jan 2019 11:17:19 +0000 (12:17 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 10 Jan 2019 11:17:19 +0000 (12:17 +0100)
* report failed partition type parsing
* make sure partition types code (from user reply) for MBR is hex

Reported-by: Jonny Grant <jg@jguk.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fdisk.c
libfdisk/src/parttype.c

index 89fec262932228995487cb73d654e3586da9518a..3e8ebf4a30d4cc04d6473f7ae57ef1e66665a2c4 100644 (file)
@@ -493,8 +493,13 @@ static struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt, int
 
                if (buf[1] == '\0' && toupper(*buf) == 'L')
                        list_partition_types(cxt);
-               else if (*buf)
-                       return fdisk_label_parse_parttype(lb, buf);
+               else if (*buf) {
+                       struct fdisk_parttype *t = fdisk_label_parse_parttype(lb, buf);
+
+                       if (!t)
+                               fdisk_info(cxt, _("Failed to parse '%s' partition type."), buf);
+                       return t;
+               }
         } while (1);
 
        return NULL;
@@ -621,7 +626,7 @@ void change_partition_type(struct fdisk_context *cxt)
                        break;
        } while (!t);
 
-       if (canceled == 0 && fdisk_set_partition_type(cxt, i, t) == 0)
+       if (canceled == 0 && t && fdisk_set_partition_type(cxt, i, t) == 0)
                fdisk_info(cxt,
                        _("Changed type of partition '%s' to '%s'."),
                        old, t ? fdisk_parttype_get_name(t) : _("Unknown"));
index 5b4be6c3a3ab5dfe95fca7e43ce5f3b9da7611dd..110ef3ba76ece60055b867124ce1732546542470 100644 (file)
@@ -313,9 +313,11 @@ struct fdisk_parttype *fdisk_label_parse_parttype(
                                str, lb->name));
        types = lb->parttypes;
 
-       if (types[0].typestr == NULL && isxdigit(*str)) {
+       if (types[0].typestr == NULL) {
                unsigned int code = 0;
 
+               DBG(LABEL, ul_debugobj(lb, " parsing hex"));
+
                errno = 0;
                code = strtol(str, &end, 16);
 
@@ -331,6 +333,8 @@ struct fdisk_parttype *fdisk_label_parse_parttype(
        } else {
                int i;
 
+               DBG(LABEL, ul_debugobj(lb, " parsing string"));
+
                /* maybe specified by type string (e.g. UUID) */
                ret = fdisk_label_get_parttype_from_string(lb, str);
                if (ret)