call to ‘fprintf’ from within signal handler [CWE-479]

Mark Wielaard mark@klomp.org
Thu Jul 16 13:55:40 GMT 2020


Hi Jeffrey,

On Thu, 2020-07-16 at 04:49 -0400, Jeffrey Walton via Bzip2-devel
wrote:
> I'm testing a build with the GCC 10 analyzer. Add -fanalyzer to
> CFLAGS. If you need GCC 10, then you can find it on Fedora 32.

The GCC -fanalyzer is indeed awesome!

> The Analyzer is producing a finding:
> 
> bzip2.c:677:4: warning: call to ‘fprintf’ from within signal handler
> [CWE-479] [-Wanalyzer-unsafe-call-within-signal-handler]
>   677 |    fprintf (
>       |    ^~~~~~~~~
>   678 |       stderr,
>       |       ~~~~~~~
>   679 |       "\tInput file = %s, output file = %s\n",
>       |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   680 |       inName, outName
>       |       ~~~~~~~~~~~~~~~
>   681 |    );
> 
> There are two additional findings that are similar.

That should already have been fixed in git:

commit 8ca1faa31f396d94ab927b257f3a05236c84e330
Author: Mark Wielaard <mark@klomp.org>
Date:   Sun May 17 20:02:31 2020 +0200

    Don't call unsafe functions from SIGSEGV/SIGBUS signal handler.
    
    GCC10 -fanalyzer notices that we try to call functions that are not
    signal safe from our fatal signal handler:
    
    bzip2.c: In function ‘mySIGSEGVorSIGBUScatcher’:
    bzip2.c:819:7: warning: call to ‘fprintf’ from within signal handler
                   [CWE-479] [-Wanalyzer-unsafe-call-within-signal-handler]
    
    It also notices we then call showFileNames and cleanupAndFail which
    also call possibly not signal safe functions.
    
    Just write out the error message directly to STDERR and exit without
    trying to clean up any files.


More information about the Bzip2-devel mailing list