linux-user/elfload: Disable core dump if getrlimit fails
authorRichard Henderson <richard.henderson@linaro.org>
Tue, 27 Feb 2024 01:58:52 +0000 (15:58 -1000)
committerRichard Henderson <richard.henderson@linaro.org>
Thu, 29 Feb 2024 18:47:55 +0000 (08:47 -1000)
Do not dump core at all if getrlimit fails; this ensures
that dumpsize is valid throughout the function, not just
for the initial test vs rlim_cur.

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
linux-user/elfload.c

index b8eef893d0c77fa4acf23b971f132ec112c6dd2c..fb47fe39c90ca812c224c708848adf92c1505d68 100644 (file)
@@ -4673,7 +4673,7 @@ static int elf_core_dump(int signr, const CPUArchState *env)
         return 0;
     }
 
-    if (getrlimit(RLIMIT_CORE, &dumpsize) == 0 && dumpsize.rlim_cur == 0) {
+    if (getrlimit(RLIMIT_CORE, &dumpsize) < 0 || dumpsize.rlim_cur == 0) {
         return 0;
     }