loader: zfs_fmtdev can crash when pool discovery did fail and we have no spa

When zfs probe did fail and no spa was created, but zfs_fmtdev() is called,
we will crash while dereferencing spa (NULL pointer dereference).

MFC after:	1 week
This commit is contained in:
Toomas Soome 2019-10-19 08:08:06 +00:00
parent 01a69565d8
commit 6b74887f03
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=353757

View File

@ -769,11 +769,16 @@ zfs_fmtdev(void *vdev)
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
return (buf);
if (dev->pool_guid == 0) {
spa = STAILQ_FIRST(&zfs_pools);
/* Do we have any pools? */
spa = STAILQ_FIRST(&zfs_pools);
if (spa == NULL)
return (buf);
if (dev->pool_guid == 0)
dev->pool_guid = spa->spa_guid;
} else
else
spa = spa_find_by_guid(dev->pool_guid);
if (spa == NULL) {
printf("ZFS: can't find pool by guid\n");
return (buf);