]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
linux-user/gen-vdso: Handle fseek() failure
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 10 Jul 2025 17:07:06 +0000 (18:07 +0100)
committerRichard Henderson <richard.henderson@linaro.org>
Thu, 10 Jul 2025 17:57:35 +0000 (11:57 -0600)
Coverity points out that we don't check for fseek() failure in gen-vdso.c,
and so we might pass -1 to malloc(). Add the error checking.

(This is a standalone executable that doesn't link against glib, so
we can't do the easy thing and use g_file_get_contents().)

Coverity: CID 1523742
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250710170707.1299926-2-peter.maydell@linaro.org>

linux-user/gen-vdso.c

index fce9d5cbc3c0b2b739d781ce26074f6bda7c5483..1c406d1b10f064402838c6497024d9e54ffe7610 100644 (file)
@@ -113,9 +113,16 @@ int main(int argc, char **argv)
      * We expect the vdso to be small, on the order of one page,
      * therefore we do not expect a partial read.
      */
-    fseek(inf, 0, SEEK_END);
+    if (fseek(inf, 0, SEEK_END) < 0) {
+        goto perror_inf;
+    }
     total_len = ftell(inf);
-    fseek(inf, 0, SEEK_SET);
+    if (total_len < 0) {
+        goto perror_inf;
+    }
+    if (fseek(inf, 0, SEEK_SET) < 0) {
+        goto perror_inf;
+    }
 
     buf = malloc(total_len);
     if (buf == NULL) {