summaryrefslogtreecommitdiffstats
path: root/softmmu
diff options
context:
space:
mode:
authorPeter Maydell2021-08-12 17:15:25 +0200
committerPeter Maydell2021-08-26 18:02:00 +0200
commit8efdb7ba1b2acce9fb63ccc2e7982e19fdf5be86 (patch)
tree190bb5a8afdc8149786992b58ce95ef9a3b0f40e /softmmu
parentsoftmmu/physmem.c: Remove unneeded NULL check in qemu_ram_alloc_from_fd() (diff)
downloadqemu-8efdb7ba1b2acce9fb63ccc2e7982e19fdf5be86.tar.gz
qemu-8efdb7ba1b2acce9fb63ccc2e7982e19fdf5be86.tar.xz
qemu-8efdb7ba1b2acce9fb63ccc2e7982e19fdf5be86.zip
softmmu/physmem.c: Check return value from realpath()
The realpath() function can return NULL on error, so we need to check for it to avoid crashing when we try to strstr() into it. This can happen if we run out of memory, or if /sys/ is not mounted, among other situations. Fixes: Coverity 1459913, 1460474 Fixes: ce317be98db0 ("exec: fetch the alignment of Linux devdax pmem character device nodes") Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Jingqi Liu <jingqi.liu@intel.com> Message-id: 20210812151525.31456-1-peter.maydell@linaro.org
Diffstat (limited to 'softmmu')
-rw-r--r--softmmu/physmem.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 31baf3a887..23e77cb771 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -1451,6 +1451,9 @@ static int64_t get_file_align(int fd)
path = g_strdup_printf("/sys/dev/char/%d:%d",
major(st.st_rdev), minor(st.st_rdev));
rpath = realpath(path, NULL);
+ if (!rpath) {
+ return -errno;
+ }
rc = daxctl_new(&ctx);
if (rc) {