[PATCH 1/2] linux-user/elfload: Don't close an unopened file descriptor

Richard Henderson posted 2 patches 8 months, 3 weeks ago
Maintainers: Laurent Vivier <laurent@vivier.eu>
[PATCH 1/2] linux-user/elfload: Don't close an unopened file descriptor
Posted by Richard Henderson 8 months, 3 weeks ago
Fixes Coverity CID: 1534964
Fixes: 106f8da664 ("linux-user/elfload: Open core file after vma_init")
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 0c299a7c15..8565b9520a 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -4522,7 +4522,9 @@ static int elf_core_dump(int signr, const CPUArchState *env)
     ret = -errno;
     mmap_unlock();
     cpu_list_unlock();
-    close(fd);
+    if (fd >= 0) {
+        close(fd);
+    }
     return ret;
 }
 #endif /* USE_ELF_CORE_DUMP */
-- 
2.34.1
Re: [PATCH 1/2] linux-user/elfload: Don't close an unopened file descriptor
Posted by Philippe Mathieu-Daudé 8 months, 3 weeks ago
On 6/3/24 00:39, Richard Henderson wrote:
> Fixes Coverity CID: 1534964
> Fixes: 106f8da664 ("linux-user/elfload: Open core file after vma_init")
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   linux-user/elfload.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>