]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (script) make sure label is specified
authorKarel Zak <kzak@redhat.com>
Wed, 12 Aug 2020 13:52:53 +0000 (15:52 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 12 Aug 2020 13:52:53 +0000 (15:52 +0200)
and unref type if already specified (unlikely, but be paranoid)

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/parttype.c
libfdisk/src/script.c

index e3eb0cffaf8577de8b0ef249e1bf57b46990367c..ec5debca7a9537eef74f81905f82dc2a8f5e8487 100644 (file)
@@ -438,7 +438,7 @@ struct fdisk_parttype *fdisk_label_advparse_parttype(
        struct fdisk_parttype *res = NULL;
        unsigned int code = 0;
 
-       if (!lb->nparttypes)
+       if (!lb || lb->nparttypes)
                return NULL;
 
        DBG(LABEL, ul_debugobj(lb, "parsing '%s' (%s) type", str, lb->name));
index 051fa326e9a8c8bc9ec0214e1ec72cb3c9d1dd75..d18ba573761530dc182ac324bc0490c700ef2e32 100644 (file)
@@ -1075,7 +1075,7 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s)
 
                } else if (!strncasecmp(p, "type=", 5) ||
                           !strncasecmp(p, "Id=", 3)) {         /* backward compatibility */
-                       char *type;
+                       char *type = NULL;
 
                        p += ((*p == 'I' || *p == 'i') ? 3 : 5); /* "Id=", "type=" */
 
@@ -1083,14 +1083,12 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s)
                        if (rc)
                                break;
 
+                       fdisk_unref_parttype(pa->type);
                        pa->type = fdisk_label_advparse_parttype(script_get_label(dp),
                                        type, FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS);
                        free(type);
-
-                       if (!pa->type) {
+                       if (!pa->type)
                                rc = -EINVAL;
-                               break;
-                       }
                } else {
                        DBG(SCRIPT, ul_debugobj(dp, "script parse error: unknown field '%s'", p));
                        rc = -EINVAL;
@@ -1201,10 +1199,10 @@ static int parse_line_valcommas(struct fdisk_script *dp, char *s)
                        if (rc)
                                break;
 
+                       fdisk_unref_parttype(pa->type);
                        pa->type = fdisk_label_advparse_parttype(script_get_label(dp),
                                                str, FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS);
                        free(str);
-
                        if (!pa->type)
                                rc = -EINVAL;
                        break;