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: ce317be98d
("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
This commit is contained in:
parent
8f1bdb0ea1
commit
8efdb7ba1b
@ -1451,6 +1451,9 @@ static int64_t get_file_align(int fd)
|
|||||||
path = g_strdup_printf("/sys/dev/char/%d:%d",
|
path = g_strdup_printf("/sys/dev/char/%d:%d",
|
||||||
major(st.st_rdev), minor(st.st_rdev));
|
major(st.st_rdev), minor(st.st_rdev));
|
||||||
rpath = realpath(path, NULL);
|
rpath = realpath(path, NULL);
|
||||||
|
if (!rpath) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
rc = daxctl_new(&ctx);
|
rc = daxctl_new(&ctx);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
Loading…
Reference in New Issue
Block a user