zfsboot: Fix startup crash

On a FreeNAS mini XL, with geli encrypted drives the loader crashed in
geli_read().

When we iterate over the list of disks and allocate the zfsdsk structures we
don’t zero out the gdev pointer. In one case that resulted in geli_read()
(called on the bogus pointer) dividing by zero.

Use calloc() to ensure the zfsdsk structure is always zeroed, so the pointer is
initialised to NULL. As a side benefit it gets rid of one #ifdef
LOADER_GELI_SUPPORT.
This commit is contained in:
Kristof Provost 2018-08-05 11:15:28 +00:00
parent 26f3e847c3
commit 5abe8cb6de

View File

@ -707,10 +707,7 @@ main(void)
}
setheap(heap_next, heap_end);
zdsk = malloc(sizeof(struct zfsdsk));
#ifdef LOADER_GELI_SUPPORT
zdsk->gdev = NULL;
#endif
zdsk = calloc(1, sizeof(struct zfsdsk));
zdsk->dsk.drive = *(uint8_t *)PTOV(ARGS);
zdsk->dsk.type = zdsk->dsk.drive & DRV_HARD ? TYPE_AD : TYPE_FD;
zdsk->dsk.unit = zdsk->dsk.drive & DRV_MASK;
@ -758,7 +755,7 @@ main(void)
if (!int13probe(i | DRV_HARD))
break;
zdsk = malloc(sizeof(struct zfsdsk));
zdsk = calloc(1, sizeof(struct zfsdsk));
zdsk->dsk.drive = i | DRV_HARD;
zdsk->dsk.type = zdsk->dsk.drive & TYPE_AD;
zdsk->dsk.unit = i;