libfdisk: (gpt) care about SSIZE_MAX for read(2)

read(2) behavior is undefined if you want to read more  than SSIZE_MAX
bytes. Let's be paranoid and check for this...

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2017-04-06 12:13:46 +02:00
parent 9e320545bb
commit a8294f401f
1 changed files with 5 additions and 0 deletions

View File

@ -874,6 +874,11 @@ static unsigned char *gpt_read_entries(struct fdisk_context *cxt,
if (gpt_sizeof_ents(header, &sz))
return NULL;
if (sz > (size_t) SSIZE_MAX) {
DBG(LABEL, ul_debug("GPT entries array too large to read()"));
return NULL;
}
ret = calloc(1, sz);
if (!ret)
return NULL;