Skip to content
This repository was archived by the owner on Apr 5, 2026. It is now read-only.

Commit 38dd0f5

Browse files
committed
ci: fix ASan self-test — use -M 0 and re-introduce real bug
The standalone toy program proved the toolchain works, but couldn't catch real proxy bugs. Switch back to re-introducing the actual CONN_INFO heap overflow (a7e832e). Root cause of prior failure: with -M 1, the bug triggers in the forked child worker (workers=0), but $! captures the parent PID. ASan output from the child was lost. Fix: use -M 0 (single process, no fork) so the bug fires in the main process whose stderr we capture. Also: use separate ports (7443/7888) to avoid conflicts with the clean test, and redirect both stdout+stderr to the log.
1 parent ca26c91 commit 38dd0f5

1 file changed

Lines changed: 35 additions & 20 deletions

File tree

.github/workflows/test.yml

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -207,27 +207,42 @@ jobs:
207207
fi
208208
echo "No ASan errors detected"
209209
210-
- name: Verify ASan is active (self-test)
211-
run: |
212-
# Build and run a trivial heap-buffer-overflow to prove the ASan
213-
# toolchain is working. If flags are wrong or the runtime is
214-
# missing, this step fails.
215-
cat > /tmp/asan-selftest.c <<'CEOF'
216-
#include <stdlib.h>
217-
#include <string.h>
218-
int main(void) {
219-
char *p = malloc(8);
220-
memset(p, 'A', 32); /* 24 bytes past allocation */
221-
free(p);
222-
return 0;
223-
}
224-
CEOF
225-
cc -fsanitize=address -fno-omit-frame-pointer -o /tmp/asan-selftest /tmp/asan-selftest.c
210+
- name: Verify ASan catches known heap overflow
211+
run: |
212+
# Re-introduce the CONN_INFO heap overflow fixed in a7e832e to
213+
# prove ASan catches real bugs in the proxy, not just toy programs.
214+
#
215+
# The bug: CONN_INFO(LC)->window_clamp writes at offset ~512 into
216+
# an 80-byte listening_connection_info (allocated via malloc).
217+
#
218+
# Key: use -M 0 (no fork) so the bug triggers in the main process
219+
# whose stderr we capture. With -M 1, the bug only fires in the
220+
# child worker, but $! captures the parent PID.
221+
sed -i 's/LISTEN_CONN_INFO(LC)->window_clamp/CONN_INFO(LC)->window_clamp/' mtproto/mtproto-proxy.c
222+
223+
make -j$(nproc) \
224+
EXTRA_CFLAGS="-fsanitize=address -fno-omit-frame-pointer" \
225+
EXTRA_LDFLAGS="-fsanitize=address"
226+
cp objs/bin/mtproto-proxy mtproxy-run/
227+
228+
cd mtproxy-run
229+
ASAN_OPTIONS=detect_leaks=0 \
230+
./mtproto-proxy -u nobody -p 7888 -H 7443 -S $MTPROXY_SECRET \
231+
--http-stats --aes-pwd proxy-secret proxy-multi.conf -M 0 \
232+
>asan-bug.log 2>&1 &
233+
BUG_PID=$!
234+
sleep 5
235+
kill "$BUG_PID" 2>/dev/null; wait "$BUG_PID" 2>/dev/null || true
226236
227-
if /tmp/asan-selftest 2>&1 | grep -q "heap-buffer-overflow"; then
228-
echo "ASan self-test passed — sanitizer is active"
237+
if grep -q "heap-buffer-overflow" asan-bug.log; then
238+
echo "ASan correctly detected the known heap-buffer-overflow"
229239
else
230-
echo "::error::ASan self-test failed — sanitizer did not detect heap-buffer-overflow"
231-
/tmp/asan-selftest 2>&1 || true
240+
echo "::error::ASan did NOT detect the known heap overflow"
241+
echo "--- asan-bug.log ---"
242+
cat asan-bug.log
232243
exit 1
233244
fi
245+
246+
- name: Restore source tree
247+
if: always()
248+
run: git checkout -- mtproto/mtproto-proxy.c

0 commit comments

Comments
 (0)