-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathDockerfile-asan-test
More file actions
99 lines (86 loc) · 3.54 KB
/
Copy pathDockerfile-asan-test
File metadata and controls
99 lines (86 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Dockerfile for reproducing the ASAN ODR violation (GitHub Issue #1632)
#
# This builds PHP from source with AddressSanitizer enabled, then builds
# both sqlsrv and pdo_sqlsrv extensions and attempts to load them together.
#
# Usage:
# docker build -f Dockerfile-asan-test -t msphpsql-asan-test .
# docker run --rm msphpsql-asan-test
#
# Expected results:
# BEFORE fix: ASAN aborts with "odr-violation" on g_sqlsrv_stream_wrapper / isVistaOrGreater
# AFTER fix: php -v succeeds, both extensions load cleanly
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
ENV PHP_VERSION=8.4.8
# Install build dependencies
RUN apt-get update && apt-get install -y \
autoconf \
bison \
build-essential \
curl \
libcurl4-openssl-dev \
libonig-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
libxml2-dev \
pkg-config \
re2c \
unixodbc-dev \
zlib1g-dev \
&& apt-get clean
# Download and build PHP from source with ASAN
WORKDIR /tmp
RUN curl -fSL https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz -o php.tar.gz \
&& tar xzf php.tar.gz \
&& cd php-${PHP_VERSION} \
&& ./configure \
--prefix=/usr/local \
--enable-debug \
--enable-address-sanitizer \
--enable-pdo \
--with-pdo-odbc=unixODBC,/usr \
--without-pear \
--disable-cgi \
--disable-phpdbg \
&& make -j$(nproc) \
&& make install \
&& cd / && rm -rf /tmp/php*
# Verify PHP was built with ASAN
RUN php -v 2>&1 | head -5 || true
# Copy extension source and clean any build artifacts
WORKDIR /build
COPY source/ /build/source/
RUN cd /build/source/sqlsrv && rm -rf .libs build modules *.lo *.la *.dep Makefile* config.h config.log config.nice config.status configure configure~ libtool run-tests.php acinclude.m4 aclocal.m4 autom4te.cache 2>/dev/null; true
RUN cd /build/source/pdo_sqlsrv && rm -rf .libs build modules *.lo *.la *.dep Makefile* config.h config.log config.nice config.status configure configure~ libtool run-tests.php acinclude.m4 aclocal.m4 autom4te.cache 2>/dev/null; true
# Run packagize to copy shared/ into each extension dir
WORKDIR /build/source
RUN sed -i 's/\r$//' packagize.sh && chmod +x packagize.sh && bash packagize.sh
# Build sqlsrv extension (with ASAN flags to match PHP)
WORKDIR /build/source/sqlsrv
RUN phpize \
&& ./configure CXXFLAGS="-fsanitize=address -fno-omit-frame-pointer -g" LDFLAGS="-fsanitize=address" \
&& make -j$(nproc) \
&& make install
# Build pdo_sqlsrv extension (with ASAN flags to match PHP)
WORKDIR /build/source/pdo_sqlsrv
RUN phpize \
&& ./configure CXXFLAGS="-fsanitize=address -fno-omit-frame-pointer -g" LDFLAGS="-fsanitize=address" \
&& make -j$(nproc) \
&& make install
# Test: try to load both extensions together
# This is the step that triggers the ODR violation under ASAN
WORKDIR /
RUN echo "=== Testing: load both extensions ===" \
&& echo "If ASAN is working, this will either succeed (fix works) or abort (ODR violation):" \
&& ASAN_OPTIONS=detect_odr_violation=2 php -d extension=sqlsrv.so -d extension=pdo_sqlsrv.so -v 2>&1; \
echo "Exit code: $?"
# Also test each extension individually (should always work)
RUN echo "=== Testing: sqlsrv only ===" \
&& php -d extension=sqlsrv.so -r "echo 'sqlsrv loaded OK' . PHP_EOL;" 2>&1; \
echo "Exit code: $?"
RUN echo "=== Testing: pdo_sqlsrv only ===" \
&& php -d extension=pdo_sqlsrv.so -r "echo 'pdo_sqlsrv loaded OK' . PHP_EOL;" 2>&1; \
echo "Exit code: $?"
CMD ["bash", "-c", "echo 'ASAN ODR test complete. Check build output above.'"]