qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] softmmu/physmem.c: Check return value from realpath()


From: Liu, Jingqi
Subject: Re: [PATCH] softmmu/physmem.c: Check return value from realpath()
Date: Fri, 13 Aug 2021 15:24:45 +0800
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0


On 8/12/2021 11:15 PM, Peter Maydell wrote:
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>
---
  softmmu/physmem.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index c47cb6da2e4..eb0595d57c4 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;
+        }

Good find!

Reviewed-by: Jingqi Liu <jingqi.liu@intel.com>

Thanks,
Jingqi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]