aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2016-10-25 12:08:58 +0200
committerKarel Zak <kzak@redhat.com>2016-10-25 12:10:31 +0200
commit17d0902c89eb16df26b3458dd5da71bb0dd99e93 (patch)
treec3069715603b1ace2b2452732a1c549be8b77f74
parent42b02524de1d081422fcc610417b8dd15739c108 (diff)
downloadutil-linux-17d0902c89eb16df26b3458dd5da71bb0dd99e93.tar.gz
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>
-rw-r--r--libfdisk/src/gpt.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c
index 208699bfcd..aa83a4f67e 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++;