Skip to content

Commit eab6c19

Browse files
authored
Enable Address Sanitizer in specified CI tests (#4725)
1 parent fa7f7e2 commit eab6c19

File tree

7 files changed

+46
-10
lines changed

7 files changed

+46
-10
lines changed

.github/workflows/ci-linux.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- name: config site
5555
run: cd pjlib/include/pj && cp config_site_test.h config_site.h
5656
- name: configure
57-
run: CFLAGS="-g -fPIC" CXXFLAGS="-g -fPIC" LDFLAGS="-rdynamic" ./configure --enable-libwebrtc-aec3
57+
run: CFLAGS="-g -fPIC -fsanitize=address" CXXFLAGS="-g -fPIC -fsanitize=address" LDFLAGS="-rdynamic -fsanitize=address" ./configure --enable-libwebrtc-aec3
5858
- name: make
5959
run: $MAKE_FAST
6060
- name: swig bindings
@@ -100,11 +100,13 @@ jobs:
100100
- name: config site
101101
run: cd pjlib/include/pj && cp config_site_test.h config_site.h
102102
- name: configure
103-
run: CFLAGS="-g" LDFLAGS="-rdynamic" ./configure
103+
run: CFLAGS="-g -fsanitize=address" CXXFLAGS="-fsanitize=address" LDFLAGS="-rdynamic -fsanitize=address" ./configure
104104
- name: make
105105
run: $MAKE_FAST
106106
- name: pjlib-test
107-
run: make pjlib-test
107+
run: |
108+
export LSAN_OPTIONS="suppressions=$GITHUB_WORKSPACE/tests/sanitizers/lsan.supp"
109+
make pjlib-test
108110
- name: pjlib-util-test
109111
run: make pjlib-util-test
110112
- name: pjnath-test
@@ -130,7 +132,7 @@ jobs:
130132
- name: config site
131133
run: cd pjlib/include/pj && cp config_site_test.h config_site.h
132134
- name: configure
133-
run: CFLAGS="-g" LDFLAGS="-rdynamic" ./configure
135+
run: CFLAGS="-g -fsanitize=address" CXXFLAGS="-fsanitize=address" LDFLAGS="-rdynamic -fsanitize=address" ./configure
134136
- name: make
135137
run: $MAKE_FAST
136138
- name: pjsip-test

.github/workflows/ci-mac.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ jobs:
294294
- name: config site
295295
run: cd pjlib/include/pj && cp config_site_test.h config_site.h && echo "#define PJMEDIA_HAS_VIDEO 1" >> config_site.h
296296
- name: configure
297-
run: CFLAGS="-g $(pkg-config --cflags openssl) $(pkg-config --cflags opencore-amrnb) -DHAS_VID_CODEC_TEST=0 -fPIC" LDFLAGS="$(pkg-config --libs-only-L openssl) $(pkg-config --libs-only-L opencore-amrnb)" CXXFLAGS="-g -fPIC" ./configure
297+
run: CFLAGS="-g $(pkg-config --cflags openssl) $(pkg-config --cflags opencore-amrnb) -DHAS_VID_CODEC_TEST=0 -fPIC -fsanitize=address" LDFLAGS="$(pkg-config --libs-only-L openssl) $(pkg-config --libs-only-L opencore-amrnb) -fsanitize=address" CXXFLAGS="-g -fPIC -fsanitize=address" ./configure
298298
- name: make
299299
run: $MAKE_FAST
300300
- name: set up Python
@@ -330,7 +330,7 @@ jobs:
330330
- name: config site
331331
run: cd pjlib/include/pj && cp config_site_test.h config_site.h && echo "#define PJMEDIA_HAS_VIDEO 1" >> config_site.h
332332
- name: configure
333-
run: CFLAGS="-g $(pkg-config --cflags openssl) $(pkg-config --cflags opencore-amrnb)" LDFLAGS="$(pkg-config --libs-only-L openssl) $(pkg-config --libs-only-L opencore-amrnb)" ./configure
333+
run: CFLAGS="-g $(pkg-config --cflags openssl) $(pkg-config --cflags opencore-amrnb) -fsanitize=address" LDFLAGS="$(pkg-config --libs-only-L openssl) $(pkg-config --libs-only-L opencore-amrnb) -fsanitize=address" CXXFLAGS="-fsanitize=address" ./configure
334334
- name: make
335335
run: $MAKE_FAST
336336
- name: disable firewall
@@ -360,7 +360,7 @@ jobs:
360360
- name: config site
361361
run: cd pjlib/include/pj && cp config_site_test.h config_site.h && echo "#define PJMEDIA_HAS_VIDEO 1" >> config_site.h
362362
- name: configure
363-
run: CFLAGS="-g $(pkg-config --cflags openssl) $(pkg-config --cflags opencore-amrnb)" LDFLAGS="$(pkg-config --libs-only-L openssl) $(pkg-config --libs-only-L opencore-amrnb)" ./configure
363+
run: CFLAGS="-g $(pkg-config --cflags openssl) $(pkg-config --cflags opencore-amrnb) -fsanitize=address" LDFLAGS="$(pkg-config --libs-only-L openssl) $(pkg-config --libs-only-L opencore-amrnb) -fsanitize=address" CXXFLAGS="-fsanitize=address" ./configure
364364
- name: make
365365
run: $MAKE_FAST
366366
- name: disable firewall

pjlib-util/src/pjlib-util-test/encryption.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ int encryption_benchmark()
767767
((unsigned)(bytes) % (1024 * 1024)) / 1024));
768768
}
769769

770+
pj_pool_release(pool);
771+
770772
return 0;
771773
}
772774

pjlib/src/pj/ssl_sock_ossl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,10 +873,11 @@ static pj_status_t init_openssl(void)
873873
* SSL_free(), perhaps it is safer to obey this, the leak amount seems
874874
* to be relatively small (<500 bytes) and should occur once only in
875875
* the library lifetime.
876+
* Update 2026: reenabled since OpenSSL 1.0.x has been EOL since 2019.
877+
*/
876878
#if OPENSSL_VERSION_NUMBER >= 0x10101000L
877879
SSL_SESSION_free(ssl_sess);
878880
#endif
879-
*/
880881

881882
SSL_CTX_free(ctx);
882883
}

pjlib/src/pjlib-test/timer.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,21 @@ static int test_timer_heap(void)
204204
* bug in the implementation (note that race message is ok).
205205
*/
206206
#define RANDOMIZED_TEST 1
207-
#define SIMULATE_CRASH PJ_TIMER_USE_COPY
207+
208+
#ifndef __has_feature
209+
#define __has_feature(x) 0
210+
#endif
211+
#if defined(__SANITIZE_ADDRESS__) || \
212+
(defined(__has_feature) && __has_feature(address_sanitizer))
213+
#define ASAN_ENABLED 1
214+
#else
215+
#define ASAN_ENABLED 0
216+
#endif
217+
218+
/* We should only simulate timer crash when using duplicate and
219+
* not using ASan.
220+
*/
221+
#define SIMULATE_CRASH PJ_TIMER_USE_COPY && !ASAN_ENABLED
208222

209223
#if RANDOMIZED_TEST
210224
#define ST_STRESS_THREAD_COUNT 20

pjsip/src/test/test.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
extern pjsip_endpoint *endpt;
2727
extern pj_caching_pool caching_pool;
2828

29+
/* Check if we are using ASan */
30+
#ifndef __has_feature
31+
#define __has_feature(x) 0
32+
#endif
33+
#if defined(__SANITIZE_ADDRESS__) || \
34+
(defined(__has_feature) && __has_feature(address_sanitizer))
35+
#define ASAN_ENABLED 1
36+
#else
37+
#define ASAN_ENABLED 0
38+
#endif
39+
2940
#define TEST_UDP_PORT 15060
3041
#define TEST_UDP_PORT_STR "15060"
3142

@@ -61,7 +72,10 @@ extern pj_caching_pool caching_pool;
6172
#endif
6273

6374
#define INCLUDE_URI_TEST INCLUDE_MESSAGING_GROUP
64-
#define INCLUDE_MSG_TEST INCLUDE_MESSAGING_GROUP
75+
/* Do not run message test under ASan, as sip_parser's longjmp mechanism
76+
* will cause issues.
77+
*/
78+
#define INCLUDE_MSG_TEST (INCLUDE_MESSAGING_GROUP && !ASAN_ENABLED)
6579
#define INCLUDE_MULTIPART_TEST INCLUDE_MESSAGING_GROUP
6680
#define INCLUDE_TXDATA_TEST INCLUDE_MESSAGING_GROUP
6781
#define INCLUDE_TSX_BENCH (INCLUDE_MESSAGING_GROUP && WITH_BENCHMARK)

tests/sanitizers/lsan.supp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
leak:ASN1_STRING_set
2+
leak:PEM_ASN1_read_bio
3+
leak:libcrypto.so

0 commit comments

Comments
 (0)