pipewire/test
Barnabás Pőcze 529b6fd1b8 test: loop: add test which destroys managed source before reentering
Add a test which triggers two event sources in the loop's "before"
control hook, and destroys the second source in the loop's "after"
control hook, and then reenters the loop in the event handler of
the first source. At the moment, this test triggers a use-after-free.

==2973914==ERROR: AddressSanitizer: heap-use-after-free on address 0x608000000440 [...]
READ of size 4 at 0x608000000440 thread T0
    #0 0x7fa97f60c6b7 in loop_iterate ../spa/plugins/support/loop.c:376
    #1 0x7fa98472c1eb in pw_main_loop_run ../src/pipewire/main-loop.c:148
    #2 0x559995af7a76 in destroy_managed_source_before_dispatch_recurse ../test/test-loop.c:355
    #3 0x559995b02678 in start_test_nofork ../test/pwtest.c:882
    #4 0x559995b06191 in run_test ../test/pwtest.c:1087
    #5 0x559995b0948a in run_tests ../test/pwtest.c:1283
    #6 0x559995b0aea4 in main ../test/pwtest.c:1482
    #7 0x7fa98360130f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)
    #8 0x7fa9836013c0 in __libc_start_main@GLIBC_2.2.5 (/usr/lib/libc.so.6+0x2d3c0)
    #9 0x559995aed754 in _start (/home/pb/temp/src/pipewire/build/test/test-loop+0x26754)

0x608000000440 is located 32 bytes inside of 96-byte region [0x608000000420,0x608000000480)
freed by thread T0 here:
    #0 0x7fa984ffda79 in __interceptor_free /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x7fa97f60b03a in process_destroy ../spa/plugins/support/loop.c:344
    #2 0x7fa97f60cbf8 in loop_iterate ../spa/plugins/support/loop.c:387
    #3 0x559995af5b62 in dmsbd_recurse_on_event ../test/test-loop.c:298
    #4 0x7fa97f60d826 in source_io_func ../spa/plugins/support/loop.c:396
    #5 0x7fa97f60c7e7 in loop_iterate ../spa/plugins/support/loop.c:377
    #6 0x7fa98472c1eb in pw_main_loop_run ../src/pipewire/main-loop.c:148
    #7 0x559995af7a76 in destroy_managed_source_before_dispatch_recurse ../test/test-loop.c:355
    #8 0x559995b02678 in start_test_nofork ../test/pwtest.c:882
    #9 0x559995b06191 in run_test ../test/pwtest.c:1087
    #10 0x559995b0948a in run_tests ../test/pwtest.c:1283
    #11 0x559995b0aea4 in main ../test/pwtest.c:1482
    #12 0x7fa98360130f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)

previously allocated by thread T0 here:
    #0 0x7fa984ffdfb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fa97f60d883 in loop_add_io ../spa/plugins/support/loop.c:408
    #2 0x559995af75de in destroy_managed_source_before_dispatch_recurse ../test/test-loop.c:349
    #3 0x559995b02678 in start_test_nofork ../test/pwtest.c:882
    #4 0x559995b06191 in run_test ../test/pwtest.c:1087
    #5 0x559995b0948a in run_tests ../test/pwtest.c:1283
    #6 0x559995b0aea4 in main ../test/pwtest.c:1482
    #7 0x7fa98360130f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)

SUMMARY: AddressSanitizer: heap-use-after-free ../spa/plugins/support/loop.c:376 in loop_iterate
2022-03-06 18:40:43 +00:00
..
meson.build test: add simple functional tests 2022-03-05 17:51:22 +00:00
pwtest-compat.c treewide: only define feature macros when the feature is available 2022-02-04 00:15:59 +01:00
pwtest-implementation.h test: add errno check macros 2021-06-09 18:00:06 +10:00
pwtest.c pwtest: fix daemon log scrambling 2022-03-06 02:29:35 +02:00
pwtest.h pwtest: add pwtest_spawn for running external programs 2022-03-05 17:51:22 +00:00
test-array.c array: re-initialize the array in pw_array_clear() 2021-10-07 15:08:57 +10:00
test-client.c test: move the client and utils tests over here 2021-08-04 07:45:06 +00:00
test-config.c test: disable broken test 2022-02-01 18:15:16 +01:00
test-context.c treewide: only define feature macros when the feature is available 2022-02-04 00:15:59 +01:00
test-example.c meson.build: drop HAVE_CONFIG_H 2021-06-10 09:04:16 +10:00
test-functional.c test: add simple functional tests 2022-03-05 17:51:22 +00:00
test-lib.c test: call pw_deinit() at end of test 2022-02-08 11:34:08 +01:00
test-logger.c test: test-logger: ignore some systemd journal error codes 2021-12-01 11:13:50 +01:00
test-loop.c test: loop: add test which destroys managed source before reentering 2022-03-06 18:40:43 +00:00
test-map.c map: make _insert_at() fail on a removed item 2021-10-25 16:17:35 +02:00
test-properties.c test: move some of the property tests to pwtest 2021-06-17 07:08:53 +00:00
test-pwtest.c treewide: only define feature macros when the feature is available 2022-02-04 00:15:59 +01:00
test-spa-buffer.c test: convert two spa tests to pwtest 2021-06-09 18:00:39 +10:00
test-spa-json.c json: add spa_json_parse_stringn() 2022-01-04 12:37:00 +01:00
test-spa-log.c tests: fix log test 2021-09-29 17:06:35 +02:00
test-spa-node.c test: replace all spa_assert() macros with spa_assert_se() 2021-07-27 10:24:44 +10:00
test-spa-pod.c test: replace all spa_assert() macros with spa_assert_se() 2021-07-27 10:24:44 +10:00
test-spa-utils.c spa: add a macro to check for a callback version 2021-09-28 09:35:38 +02:00
test-support.c test: add a test for the logger truncation 2021-06-09 18:00:39 +10:00
test-utils.c test: move the client and utils tests over here 2021-08-04 07:45:06 +00:00