mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Check overflow in init(8).
This commit is contained in:
parent
92397f6042
commit
2876c44ce7
1 changed files with 3 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue