apm-agent-php
apm-agent-php copied to clipboard
Segmentation fault when 'use' non-compound name
Describe the bug Segmentation fault on "'use' statement with non-compound name ... has no effect"
To Reproduce
Using docker image "php:7.4-fpm-bullseye" or "php:8.0-fpm-bullseye" with apm-agent-php_1.4.2 installed:
docker run --rm -it php:7.4-fpm-bullseye bash
curl -fsSLo /tmp/apm.deb https://github.com/elastic/apm-agent-php/releases/download/v1.4.2/apm-agent-php_1.4.2_all.deb
dpkg -i /tmp/apm.deb
cat >test.php <<EOF
<?php
use Demo;
echo 'Did not crash' . PHP_EOL;
EOF
echo
echo 'Test without APM:'
php -delastic_apm.enabled=false test.php
echo
echo 'Test with Elastic APM:'
php -delastic_apm.enabled=true test.php # SIGSEGV
With elastic_apm.enabled=true exit code is 139. Output:
Segmentation fault
With elastic_apm.enabled=false exit code is 0. Output:
Warning: The use statement with non-compound name 'Demo' has no effect in /var/www/html/test.php on line 2 Did not crash
Expected behavior
php -delastic_apm.enabled=true ... does not segfault.
Forgot to attach a (partial) coredump: https://gist.github.com/atli-c/8b142a79e7a5527c400a7ecd82346d58
Issue still persists with newest version (v1.6):
<?php # test.php
use Demo;
echo 'End of ./test.php' . PHP_EOL;
Test in docker:
#!/usr/bin/env bash
set -e
APM_VERSION=1.6
for PHP_VERSION in 7.4 8.1 ; do
PARENT_IMAGE="php:${PHP_VERSION}-fpm-bullseye"
NEW_IMAGE="php:${PHP_VERSION}-fpm-bullseye-apm-${APM_VERSION}"
echo "### Testing ${NEW_IMAGE} (https://github.com/elastic/apm-agent-php/issues/636)"
# Build image with ElasticApm
echo -e "FROM ${PARENT_IMAGE}\nRUN curl -fsSLo /tmp/apm.deb https://github.com/elastic/apm-agent-php/releases/download/v${APM_VERSION}/apm-agent-php_${APM_VERSION}_all.deb && dpkg -i /tmp/apm.deb" | \
docker build --quiet --tag "${NEW_IMAGE}" -f - .
# Run the test
docker run --rm -it -v ${PWD}/test.php:/work/test.php:ro -w=/work ${NEW_IMAGE} \
bash -x -c 'php -delastic_apm.enabled=false test.php && php -delastic_apm.enabled=true test.php'
echo
done
Note: this might not work on aarch64/arm64 (like new Apple computers or Raspberry Pi OS 64bit)
I can no longer replicate issue with APM_VERSION=1.7.1. It looks like this has been solved ✅