Check overflow in init(8).

This commit is contained in:
Nicholas De Nova 2017-04-01 10:07:04 -05:00
parent 92397f6042
commit 2876c44ce7
1 changed files with 3 additions and 4 deletions

View File

@ -225,14 +225,13 @@ static bool prepare_block_device(void* ctx, const char* path)
}
if ( hds_used == hds_length )
{
// TODO: Potential overflow.
size_t new_length = hds_length ? 2 * hds_length : 16;
size_t new_half_length = hds_length ? hds_length : 8;
struct harddisk** new_hds = (struct harddisk**)
reallocarray(hds, new_length, sizeof(struct harddisk*));
reallocarray(hds, new_half_length, sizeof(struct harddisk*) * 2);
if ( !new_hds )
fatal("realloc: %m");
hds = new_hds;
hds_length = new_length;
hds_length = 2 * new_half_length;
}
hds[hds_used++] = hd;
struct blockdevice* bdev = &hd->bdev;