Skip to content

Commit 6a2ed51

Browse files
committed
Fix UBSAN errors in ccache-swig
ccache.c:738:18: runtime error: null pointer passed as argument 1, which is declared to never be null Fixes stderr redirect in testname CCACHE_CPP2, when the CCACHE_CPP2 environment variable is defined. mdfour.c:91:20: runtime error: left shift of 139 by 24 places cannot be represented in type 'int' Looks like this brings some stability to the md4 hash calculation. Closes swig#2449 Conflicts: CHANGES.current
1 parent c8fd30b commit 6a2ed51

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CCache/ccache.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,15 @@ static void from_cache(int first)
735735
}
736736

737737
/* send the cpp stderr, if applicable */
738-
fd_cpp_stderr = open(cpp_stderr, O_RDONLY | O_BINARY);
739-
if (fd_cpp_stderr != -1) {
740-
copy_fd(fd_cpp_stderr, 2);
741-
close(fd_cpp_stderr);
742-
unlink(cpp_stderr);
743-
free(cpp_stderr);
744-
cpp_stderr = NULL;
738+
if (cpp_stderr) {
739+
fd_cpp_stderr = open(cpp_stderr, O_RDONLY | O_BINARY);
740+
if (fd_cpp_stderr != -1) {
741+
copy_fd(fd_cpp_stderr, 2);
742+
close(fd_cpp_stderr);
743+
unlink(cpp_stderr);
744+
free(cpp_stderr);
745+
cpp_stderr = NULL;
746+
}
745747
}
746748

747749
/* send the stderr */

CCache/mdfour.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ static void copy64(uint32 *M, const unsigned char *in)
8888
int i;
8989

9090
for (i=0;i<16;i++)
91-
M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) |
92-
(in[i*4+1]<<8) | (in[i*4+0]<<0);
91+
M[i] = ((uint32)in[i*4+3]<<24) | ((uint32)in[i*4+2]<<16) |
92+
((uint32)in[i*4+1]<<8) | ((uint32)in[i*4+0]<<0);
9393
}
9494

9595
static void copy4(unsigned char *out,uint32 x)

CHANGES.current

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.1.1 (in progress)
88
===========================
99

10+
2022-11-26: wsfulton
11+
#2449 Fix undefined behaviour in ccache-swig calculating md4 hashes and possibly
12+
also handling errors when CCACHE_CPP2 is set.
13+
1014
2022-11-25: wsfulton
1115
#961 Fix syntax error parsing unnamed template parameters with a default value.
1216

0 commit comments

Comments
 (0)