Skip to content

Commit b0f4c90

Browse files
peffgitster
authored andcommitted
t: support clang/gcc AddressSanitizer
When git is compiled with "-fsanitize=address" (using clang or gcc >= 4.8), all invocations of git will check for buffer overflows. This is similar to running with valgrind, except that it is more thorough (because of the compiler support, function-local buffers can be checked, too) and runs much faster (making it much less painful to run the whole test suite with the checks turned on). Unlike valgrind, the magic happens at compile-time, so we don't need the same infrastructure in the test suite that we did to support --valgrind. But there are two things we can help with: 1. On some platforms, the leak-detector is on by default, and causes every invocation of "git init" (and thus every test script) to fail. Since running git with the leak detector is pointless, let's shut it off automatically in the tests, unless the user has already configured it. 2. When apache runs a CGI, it clears the environment of unknown variables. This means that the $ASAN_OPTIONS config doesn't make it to git-http-backend, and it dies due to the leak detector. Let's mark the variable as OK for apache to pass. With these two changes, running make CC=clang CFLAGS=-fsanitize=address test works out of the box. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c18b867 commit b0f4c90

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

t/lib-httpd/apache.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ LockFile accept.lock
6969
PassEnv GIT_VALGRIND
7070
PassEnv GIT_VALGRIND_OPTIONS
7171
PassEnv GNUPGHOME
72+
PassEnv ASAN_OPTIONS
7273

7374
Alias /dumb/ www/
7475
Alias /auth/dumb/ www/auth/dumb/

t/test-lib.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ else
140140
}
141141
fi
142142

143+
: ${ASAN_OPTIONS=detect_leaks=0}
144+
export ASAN_OPTIONS
145+
143146
# Protect ourselves from common misconfiguration to export
144147
# CDPATH into the environment
145148
unset CDPATH

0 commit comments

Comments
 (0)