From ce528a26549f9456d5126f40347af44e69f448c1 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Fri, 26 Jan 2024 20:27:20 +1000 Subject: [PATCH] libalpm/discspace.c: ensure mount points provide directories In the very unlikely situtation where getmntent() and friends return non-null, but the mount directory is NULL, a null dereference could occur. It is unclear what the best course of action is in this case, so just move on to the next mount point. Signed-off-by: Allan McRae --- lib/libalpm/diskspace.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c index f0d1499d..8a2157f3 100644 --- a/lib/libalpm/diskspace.c +++ b/lib/libalpm/diskspace.c @@ -111,6 +111,10 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) } while((mnt = getmntent(fp))) { + if(mnt->mnt_dir == NULL) { + continue; + } + CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); STRDUP(mp->mount_dir, mnt->mnt_dir, free(mp); RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); mp->mount_dir_len = strlen(mp->mount_dir); @@ -134,6 +138,10 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) } while((ret = getmntent(fp, &mnt)) == 0) { + if(mnt->mnt_mountp == NULL) { + continue; + } + CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); STRDUP(mp->mount_dir, mnt->mnt_mountp, free(mp); RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); mp->mount_dir_len = strlen(mp->mount_dir); @@ -161,6 +169,10 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) } for(; entries-- > 0; fsp++) { + if(fsp->f_mntonname == NULL) { + continue; + } + CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); STRDUP(mp->mount_dir, fsp->f_mntonname, free(mp); RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); mp->mount_dir_len = strlen(mp->mount_dir);