Skip to content

Commit d1027a4

Browse files
authored
Fix | Access token identity leaking across pooled connections (#1592)
* Mock TDS server plus access token + connection pool tests for issue #1396 * Fix | An existing connection in the connection pool is reused unexpectedly even though it has a different access token. Fixes #1396 Properly implement access token handling to support pooling connections. Mock TDS server implementation allows testing of FedAuth connections without Azure configuration. Prepend MSPHPSQL to APP access token hash to ensure unique pool key. * Implement access token caching to ensure pointer stability and prevent use-after-free issues. * Detect borked tests and make build_drivers.py ts/nts option case insensitve to simplify calling logic.
1 parent 3c514aa commit d1027a4

14 files changed

Lines changed: 3230 additions & 29 deletions

.gitignore

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ __pycache__
44
*.diff
55
*.exp
66
*.log
7-
*.sh
87
*.out
9-
test/**/**/*.php
8+
*.so
9+
source/**/.libs
10+
source/**/build
11+
source/**/modules
12+
source/pdo_sqlsrv/shared
13+
source/sqlsrv/shared
14+
source/**/autom4te.cache
15+
source/**/*.dep
16+
source/**/*.la
17+
source/**/*.lo
18+
source/**/config.h*
19+
source/**/config.nice
20+
source/**/config.status
21+
source/**/configure*
22+
source/**/libtool
23+
source/**/Makefile*
24+
source/**/run-tests.php
25+
buildscripts/php*.dll
26+
buildscripts/php*.pdb

azure-pipelines.yml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,25 @@ jobs:
384384
# Set TEST_PHP_ARGS
385385
export TEST_PHP_ARGS="-c $PHP_INI"
386386
387+
# Track test failures and borked tests
388+
sqlsrv_failed=0
389+
pdo_failed=0
390+
sqlsrv_borked=0
391+
pdo_borked=0
392+
387393
echo "Running sqlsrv tests..."
388394
$PHP_BIN run-tests.php -p $PHP_BIN -c $PHP_INI -P sqlsrv/*.phpt --no-color 2>&1 | tee sqlsrv-macos.log || true
389395
396+
# Check for test failures and borked tests
397+
if grep -q "Tests failed.*[1-9]" sqlsrv-macos.log; then
398+
sqlsrv_failed=$(grep "Tests failed" sqlsrv-macos.log | grep -oE '[0-9]+' | head -1)
399+
echo "sqlsrv tests failed: $sqlsrv_failed"
400+
fi
401+
if grep -q "Tests borked.*[1-9]" sqlsrv-macos.log; then
402+
sqlsrv_borked=$(grep "Tests borked" sqlsrv-macos.log | grep -oE '[0-9]+' | head -1)
403+
echo "sqlsrv tests borked: $sqlsrv_borked"
404+
fi
405+
390406
# Show diff files
391407
for f in sqlsrv/*.diff; do
392408
if [[ -f "$f" ]]; then
@@ -401,6 +417,16 @@ jobs:
401417
echo "Running pdo_sqlsrv tests..."
402418
$PHP_BIN run-tests.php -p $PHP_BIN -c $PHP_INI -P pdo_sqlsrv/*.phpt --no-color 2>&1 | tee pdo_sqlsrv-macos.log || true
403419
420+
# Check for test failures and borked tests
421+
if grep -q "Tests failed.*[1-9]" pdo_sqlsrv-macos.log; then
422+
pdo_failed=$(grep "Tests failed" pdo_sqlsrv-macos.log | grep -oE '[0-9]+' | head -1)
423+
echo "pdo_sqlsrv tests failed: $pdo_failed"
424+
fi
425+
if grep -q "Tests borked.*[1-9]" pdo_sqlsrv-macos.log; then
426+
pdo_borked=$(grep "Tests borked" pdo_sqlsrv-macos.log | grep -oE '[0-9]+' | head -1)
427+
echo "pdo_sqlsrv tests borked: $pdo_borked"
428+
fi
429+
404430
# Show diff files
405431
for f in pdo_sqlsrv/*.diff; do
406432
if [[ -f "$f" ]]; then
@@ -409,7 +435,16 @@ jobs:
409435
fi
410436
done
411437
412-
echo "Tests completed!"
438+
# Fail if there are test failures or borked tests
439+
total_failed=$((${sqlsrv_failed:-0} + ${pdo_failed:-0}))
440+
total_borked=$((${sqlsrv_borked:-0} + ${pdo_borked:-0}))
441+
if [[ $total_failed -gt 0 || $total_borked -gt 0 ]]; then
442+
echo "Total test failures: $total_failed (sqlsrv: ${sqlsrv_failed:-0}, pdo_sqlsrv: ${pdo_failed:-0})"
443+
echo "Total borked tests: $total_borked (sqlsrv: ${sqlsrv_borked:-0}, pdo_sqlsrv: ${pdo_borked:-0})"
444+
exit 1
445+
else
446+
echo "All tests passed!"
447+
fi
413448
displayName: 'Run PHP Functional Tests'
414449
415450
#########################################
@@ -439,7 +474,7 @@ jobs:
439474
testResultsFormat: 'JUnit'
440475
testResultsFiles: '**/*.xml'
441476
searchFolder: '$(REPO_ROOT)/test/functional/'
442-
failTaskOnFailedTests: false
477+
failTaskOnFailedTests: true
443478
testRunTitle: 'macOS-PHP$(phpver)'
444479

445480
#########################################

build-linux.sh

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/bin/bash
2+
#
3+
# Build sqlsrv and pdo_sqlsrv PHP extensions on Linux.
4+
#
5+
# Usage:
6+
# ./build-linux.sh # build and copy output to build-output/
7+
# ./build-linux.sh --install # build and install to PHP extension dir (requires sudo)
8+
# ./build-linux.sh --clean # build, copy output, then clean intermediate files
9+
# ./build-linux.sh --clean-only # just remove build artifacts (no build)
10+
#
11+
# Output:
12+
# build-output/sqlsrv.so
13+
# build-output/pdo_sqlsrv.so
14+
15+
set -e
16+
17+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
18+
SRC_DIR="$SCRIPT_DIR/source"
19+
OUT_DIR="$SCRIPT_DIR/build-output"
20+
21+
DO_BUILD=true
22+
DO_CLEAN=false
23+
DO_INSTALL=false
24+
25+
for arg in "$@"; do
26+
case "$arg" in
27+
--clean) DO_CLEAN=true ;;
28+
--clean-only) DO_BUILD=false; DO_CLEAN=true ;;
29+
--install) DO_INSTALL=true ;;
30+
*) echo "Unknown option: $arg"; exit 1 ;;
31+
esac
32+
done
33+
34+
# Build one extension.
35+
# $1 = extension source dir (e.g. source/sqlsrv)
36+
# $2 = configure flag (e.g. --enable-sqlsrv)
37+
build_ext() {
38+
local ext_dir="$1"
39+
local configure_flag="$2"
40+
local ext_name
41+
ext_name="$(basename "$ext_dir")"
42+
43+
echo "=== Building $ext_name ==="
44+
45+
pushd "$ext_dir" > /dev/null
46+
47+
# Ensure shared/ symlink exists
48+
if [ ! -e shared ]; then
49+
ln -s ../shared shared
50+
fi
51+
52+
phpize
53+
./configure "$configure_flag"
54+
make -j"$(nproc)"
55+
56+
popd > /dev/null
57+
}
58+
59+
# Copy built .so to output dir.
60+
collect_output() {
61+
mkdir -p "$OUT_DIR"
62+
cp "$SRC_DIR/sqlsrv/modules/sqlsrv.so" "$OUT_DIR/"
63+
cp "$SRC_DIR/pdo_sqlsrv/modules/pdo_sqlsrv.so" "$OUT_DIR/"
64+
echo ""
65+
echo "=== Extensions copied to build-output/ ==="
66+
ls -lh "$OUT_DIR"/*.so
67+
}
68+
69+
# Remove all build artifacts from one extension dir.
70+
# $1 = extension source dir
71+
clean_ext() {
72+
local ext_dir="$1"
73+
local ext_name
74+
ext_name="$(basename "$ext_dir")"
75+
76+
echo "=== Cleaning $ext_name ==="
77+
78+
pushd "$ext_dir" > /dev/null
79+
80+
# make clean removes .lo/.la/.so/.libs etc.
81+
[ -f Makefile ] && make clean 2>/dev/null || true
82+
83+
# phpize --clean removes autoconf scaffolding
84+
[ -f configure ] && phpize --clean 2>/dev/null || true
85+
86+
# Remove the symlink we created
87+
[ -L shared ] && rm -f shared
88+
89+
popd > /dev/null
90+
}
91+
92+
# Also clean .lo/.dep files that ended up in source/shared/
93+
clean_shared() {
94+
echo "=== Cleaning shared/ build artifacts ==="
95+
find "$SRC_DIR/shared" -name '*.lo' -o -name '*.dep' -o -name '*.o' | xargs rm -f 2>/dev/null || true
96+
rm -rf "$SRC_DIR/shared/.libs" 2>/dev/null || true
97+
}
98+
99+
if $DO_BUILD; then
100+
build_ext "$SRC_DIR/sqlsrv" "--enable-sqlsrv"
101+
build_ext "$SRC_DIR/pdo_sqlsrv" "--with-pdo_sqlsrv"
102+
collect_output
103+
104+
if $DO_INSTALL; then
105+
echo ""
106+
echo "=== Installing extensions ==="
107+
pushd "$SRC_DIR/sqlsrv" > /dev/null
108+
sudo make install
109+
popd > /dev/null
110+
pushd "$SRC_DIR/pdo_sqlsrv" > /dev/null
111+
sudo make install
112+
popd > /dev/null
113+
fi
114+
fi
115+
116+
if $DO_CLEAN; then
117+
clean_ext "$SRC_DIR/sqlsrv"
118+
clean_ext "$SRC_DIR/pdo_sqlsrv"
119+
clean_shared
120+
# Remove the top-level run-tests.php copied by phpize
121+
rm -f "$SCRIPT_DIR/run-tests.php"
122+
echo ""
123+
echo "=== Build artifacts cleaned ==="
124+
fi
125+
126+
echo "Done."

buildscripts/builddrivers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def validate_php_version(version):
408408
parser = argparse.ArgumentParser()
409409
parser.add_argument('--PHPVER', help="PHP version, e.g. 7.4.* etc.")
410410
parser.add_argument('--ARCH', choices=['x64', 'x86'])
411-
parser.add_argument('--THREAD', choices=['nts', 'ts'])
411+
parser.add_argument('--THREAD', choices=['nts', 'ts'], type=str.lower)
412412
parser.add_argument('--DRIVER', default='all', choices=['all', 'sqlsrv', 'pdo_sqlsrv'], help="driver to build (default: all)")
413413
parser.add_argument('--DEBUG', action='store_true', help="enable debug mode (default: False)")
414414
parser.add_argument('--REPO', default='Microsoft', help="GitHub repository (default: Microsoft)")

0 commit comments

Comments
 (0)