apm-agent-php icon indicating copy to clipboard operation
apm-agent-php copied to clipboard

Segmentation fault when 'use' non-compound name

Open atli-c opened this issue 3 years ago • 2 comments

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.

atli-c avatar Mar 10 '22 13:03 atli-c

Forgot to attach a (partial) coredump: https://gist.github.com/atli-c/8b142a79e7a5527c400a7ecd82346d58

atli-c avatar Mar 10 '22 13:03 atli-c

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)

atli-c avatar Aug 30 '22 11:08 atli-c

I can no longer replicate issue with APM_VERSION=1.7.1. It looks like this has been solved ✅

atli-c avatar Jan 30 '23 12:01 atli-c