diff options
author | Karel Zak | 2016-10-25 12:08:58 +0200 |
---|---|---|
committer | Karel Zak | 2016-10-25 12:10:31 +0200 |
commit | 17d0902c89eb16df26b3458dd5da71bb0dd99e93 (patch) | |
tree | c3069715603b1ace2b2452732a1c549be8b77f74 /libfdisk | |
parent | Merge branch 'master' of https://github.com/yurchor/util-linux (diff) | |
download | kernel-qcow2-util-linux-17d0902c89eb16df26b3458dd5da71bb0dd99e93.tar.gz kernel-qcow2-util-linux-17d0902c89eb16df26b3458dd5da71bb0dd99e93.tar.xz kernel-qcow2-util-linux-17d0902c89eb16df26b3458dd5da71bb0dd99e93.zip |
libfdisk: (gpt) make attributes parser more robust
* 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>
Diffstat (limited to 'libfdisk')
-rw-r--r-- | libfdisk/src/gpt.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index 208699bfc..aa83a4f67 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -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++; |