aboutsummaryrefslogtreecommitdiff
path: root/bzip2.c
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2020-05-17 20:02:31 +0200
committerMark Wielaard <mark@klomp.org>2020-05-17 21:08:17 +0200
commit8ca1faa31f396d94ab927b257f3a05236c84e330 (patch)
treefc7e94d8c0be6d5673611adcddf790d11b0587fa /bzip2.c
parent4022613462968382ad707a67d2a1c4daf99a6cec (diff)
downloadbzip2-8ca1faa31f396d94ab927b257f3a05236c84e330.tar.gz
bzip2-8ca1faa31f396d94ab927b257f3a05236c84e330.tar.bz2
bzip2-8ca1faa31f396d94ab927b257f3a05236c84e330.zip
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.
Diffstat (limited to 'bzip2.c')
-rw-r--r--bzip2.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/bzip2.c b/bzip2.c
index d95d280..d1f2fa8 100644
--- a/bzip2.c
+++ b/bzip2.c
@@ -815,10 +815,9 @@ void mySignalCatcher ( IntNative n )
815static 815static
816void mySIGSEGVorSIGBUScatcher ( IntNative n ) 816void mySIGSEGVorSIGBUScatcher ( IntNative n )
817{ 817{
818 const char *msg;
818 if (opMode == OM_Z) 819 if (opMode == OM_Z)
819 fprintf ( 820 msg = ": Caught a SIGSEGV or SIGBUS whilst compressing.\n"
820 stderr,
821 "\n%s: Caught a SIGSEGV or SIGBUS whilst compressing.\n"
822 "\n" 821 "\n"
823 " Possible causes are (most likely first):\n" 822 " Possible causes are (most likely first):\n"
824 " (1) This computer has unreliable memory or cache hardware\n" 823 " (1) This computer has unreliable memory or cache hardware\n"
@@ -834,12 +833,9 @@ void mySIGSEGVorSIGBUScatcher ( IntNative n )
834 " bug report should have. If the manual is available on your\n" 833 " bug report should have. If the manual is available on your\n"
835 " system, please try and read it before mailing me. If you don't\n" 834 " system, please try and read it before mailing me. If you don't\n"
836 " have the manual or can't be bothered to read it, mail me anyway.\n" 835 " have the manual or can't be bothered to read it, mail me anyway.\n"
837 "\n", 836 "\n";
838 progName ); 837 else
839 else 838 msg = ": Caught a SIGSEGV or SIGBUS whilst decompressing.\n"
840 fprintf (
841 stderr,
842 "\n%s: Caught a SIGSEGV or SIGBUS whilst decompressing.\n"
843 "\n" 839 "\n"
844 " Possible causes are (most likely first):\n" 840 " Possible causes are (most likely first):\n"
845 " (1) The compressed data is corrupted, and bzip2's usual checks\n" 841 " (1) The compressed data is corrupted, and bzip2's usual checks\n"
@@ -857,13 +853,25 @@ void mySIGSEGVorSIGBUScatcher ( IntNative n )
857 " bug report should have. If the manual is available on your\n" 853 " bug report should have. If the manual is available on your\n"
858 " system, please try and read it before mailing me. If you don't\n" 854 " system, please try and read it before mailing me. If you don't\n"
859 " have the manual or can't be bothered to read it, mail me anyway.\n" 855 " have the manual or can't be bothered to read it, mail me anyway.\n"
860 "\n", 856 "\n";
861 progName ); 857 write ( STDERR_FILENO, "\n", 1 );
862 858 write ( STDERR_FILENO, progName, strlen ( progName ) );
863 showFileNames(); 859 write ( STDERR_FILENO, msg, strlen ( msg ) );
864 if (opMode == OM_Z) 860
865 cleanUpAndFail( 3 ); else 861 msg = "\tInput file = ";
866 { cadvise(); cleanUpAndFail( 2 ); } 862 write ( STDERR_FILENO, msg, strlen (msg) );
863 write ( STDERR_FILENO, inName, strlen (inName) );
864 write ( STDERR_FILENO, "\n", 1 );
865 msg = "\tOutput file = ";
866 write ( STDERR_FILENO, msg, strlen (msg) );
867 write ( STDERR_FILENO, outName, strlen (outName) );
868 write ( STDERR_FILENO, "\n", 1 );
869
870 /* Don't call cleanupAndFail. If we ended up here something went
871 terribly wrong. Trying to clean up might fail spectacularly. */
872
873 if (opMode == OM_Z) setExit(3); else setExit(2);
874 _exit(exitValue);
867} 875}
868 876
869 877