aboutsummaryrefslogtreecommitdiffstats
path: root/libfdisk/src/script.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2020-08-14 11:13:50 +0200
committerKarel Zak <kzak@redhat.com>2020-08-14 11:13:50 +0200
commit1f50296c0f2384f474e3bbd92926edea53c3bace (patch)
treec9afd48ae4c080a08d9ba555398a58acab3ebc15 /libfdisk/src/script.c
parent678d03cc8a9c665ba989b098a9be903ede72f554 (diff)
downloadutil-linux-1f50296c0f2384f474e3bbd92926edea53c3bace.tar.gz
libfdisk: (script) fix possible partno overflow
Addresses: https://oss-fuzz.com/testcase-detail/5740890480705536 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/script.c')
-rw-r--r--libfdisk/src/script.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c
index 74ff43b739..37a5a3edc3 100644
--- a/libfdisk/src/script.c
+++ b/libfdisk/src/script.c
@@ -959,7 +959,7 @@ static int next_string(char **s, char **str)
static int partno_from_devname(char *s)
{
- int pno;
+ intmax_t num;
size_t sz;
char *end, *p;
@@ -975,10 +975,15 @@ static int partno_from_devname(char *s)
return -1;
end = NULL;
errno = 0;
- pno = strtol(p, &end, 10);
+ num = strtol(p, &end, 10);
if (errno || !end || p == end)
return -1;
- return pno - 1;
+
+ if (num < INT32_MIN || num > INT32_MAX) {
+ errno = ERANGE;
+ return -1;
+ }
+ return num - 1;
}
#define FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS \