]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) make attributes parser more robust
authorKarel Zak <kzak@redhat.com>
Tue, 25 Oct 2016 10:08:58 +0000 (12:08 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 25 Oct 2016 10:10:31 +0000 (12:10 +0200)
* allow GUID: prefix only for numbers
* require space or comma separator

Addresses: https://github.com/karelzak/util-linux/issues/367
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c

index 208699bfcd42b12aa921c7165092489d361ff0f9..aa83a4f67e1211aeef85506199293009788d0874 100644 (file)
@@ -1583,10 +1583,7 @@ static int gpt_entry_attrs_from_string(
 
                DBG(LABEL, ul_debug(" parsing item '%s'", p));
 
-               if (strncmp(p, "GUID:", 5) == 0) {
-                       p += 5;
-                       continue;
-               } else if (strncmp(p, GPT_ATTRSTR_REQ,
+               if (strncmp(p, GPT_ATTRSTR_REQ,
                                        sizeof(GPT_ATTRSTR_REQ) - 1) == 0) {
                        bit = GPT_ATTRBIT_REQ;
                        p += sizeof(GPT_ATTRSTR_REQ) - 1;
@@ -1602,9 +1599,16 @@ static int gpt_entry_attrs_from_string(
                                        sizeof(GPT_ATTRSTR_NOBLOCK) - 1) == 0) {
                        bit = GPT_ATTRBIT_NOBLOCK;
                        p += sizeof(GPT_ATTRSTR_NOBLOCK) - 1;
-               } else if (isdigit((unsigned int) *p)) {
+
+               /* GUID:<bit> as well as <bit> */
+               } else if (isdigit((unsigned int) *p)
+                          || (strncmp(p, "GUID:", 5) == 0
+                              && isdigit((unsigned int) *(p + 5)))) {
                        char *end = NULL;
 
+                       if (*p == 'G')
+                               p += 5;
+
                        errno = 0;
                        bit = strtol(p, &end, 0);
                        if (errno || !end || end == str
@@ -1620,6 +1624,11 @@ static int gpt_entry_attrs_from_string(
                        return -EINVAL;
                }
 
+               if (*p && *p != ',' && !isblank(*p)) {
+                       fdisk_warnx(cxt, _("failed to parse GPT attribute string '%s'"), str);
+                       return -EINVAL;
+               }
+
                setbit(bits, bit);
 
                while (isblank(*p)) p++;