]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libasm: Fix double fclose in asm_end.
authorMark Wielaard <mark@klomp.org>
Sat, 25 Apr 2020 23:20:57 +0000 (01:20 +0200)
committerMark Wielaard <mark@klomp.org>
Sun, 26 Apr 2020 00:27:01 +0000 (02:27 +0200)
GCC10 -fanalyzer found a double fclose in asm_end. asm_end can call
text_end, which calls fclose and checks for errors, then asm_end
calls __libasm_finictx which can call fclose again (but doesn't
check for errors). Call fflush in text_end instead. fflush will
generate the same error fclose would if something went wrong writing
out the file.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libasm/ChangeLog
libasm/asm_end.c

index 7b0d3df344547a1ab4082b348b9969e62dd0d2ac..2c092abe11ac26b909f353cbc22a77679ea2eafa 100644 (file)
@@ -1,3 +1,7 @@
+2020-04-25  Mark Wielaard  <mark@klomp.org>
+
+       * asm_end.c (text_end): Call fflush instead of fclose.
+
 2020-01-08  Mark Wielaard  <mark@klomp.org>
 
        * libasm.h: Don't include libebl.h. Define an opaque Ebl handle.
index 99e9501703a8b812c84e8348d412d6dc15e5a50d..3b8582fddb7e9a70ce73e6bfd31de5e0aa253a63 100644 (file)
@@ -47,7 +47,7 @@
 static int
 text_end (AsmCtx_t *ctx __attribute__ ((unused)))
 {
-  if (fclose (ctx->out.file) != 0)
+  if (fflush (ctx->out.file) != 0)
     {
       __libasm_seterrno (ASM_E_IOERROR);
       return -1;