-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segfault when calling a PHP built-in function #421
Comments
I mean, the PHP-CPP was built with |
Here's a fully self-contained example that can be run via Docker: #!/usr/bin/env bash
set -e
cd "$(dirname -- "$(readlink -f -- "$0")")"
apt update
DEBIAN_FRONTEND=noninteractive apt install -yq php-dev git
mkdir ../build
cd ../build
git clone https://github.com/CopernicaMarketingSoftware/PHP-CPP.git
pushd PHP-CPP && make release && make install && popd
cat << EOF > crashtest.cpp
#include <phpcpp.h>
#include <iostream>
void myFunction() {
Php::call("var_export", "function call");
Php::out << std::endl << "php out" << std::endl;
}
extern "C" PHPCPP_EXPORT void *get_module() {
static Php::Extension extension("my_extension", "1.0");
extension.add<myFunction>("myFunction");
return extension;
}
EOF
g++ -shared -fPIC -o crashtest.so crashtest.cpp -lphpcpp
echo "Starting the test..."
php -dextension=./crashtest.so -r 'myFunction();'
echo "The test has been passed." Name this file docker run --rm -v"$(pwd)":/test ubuntu:18.04 bash test/run.sh The last lines will be:
Now, if you remove the
Maybe it's a problem with PHP 7.2 only, and not with PHP 7.3. |
Yes, can be the 7.2 problem, but as I saw, release only optimize the code, there is no way can be difference. Sorry for I cannot test docker test If you see Makefile, you can run in production with "make" only |
In fact, it may be Ubuntu problem. I ran the So, may be it's not a problem in PHP-CPP. Though, I can't say for sure.
There can be a difference if a code is written incorrectly (e.g. produces undefined behavior according to the standard). I encountered this situation many times before in different projects.
OK. I just wanted to show that the problem is really not on my side. Instead of Docker, you can try LXC, virtual machine or a live disk - anything that gives you a clean Ubuntu install.
As a last resort, yes. But I found out that if PHP-CPP is compiled inside a |
What the exactly php7.2 version do you have? |
On my host machine (Kubuntu 19.04):
In LXC and Docker containers (Ubuntu 18.04):
However, as I said earlier, the test is passed successfully on |
When an extension calls any built-in PHP function, it crashes, i.e. this code crashes:
Note: it only happens when PHP-CPP is built in release mode (with
make release
).Full example source code:
Build:
Test:
php -dextension=./crashtest.so -r 'myFunction();'
Output:
As mentioned above, the crash only happens when PHP-CPP is built in release mode. When PHP-CPP is built in debug mode, the output is as follows:
Which is the expected output.
Note: the crash does not happen in
Php::out
. You can remove it and the extension will still crash. I just added it to check if the test reaches that point in code.Tested on a clean Ubuntu 18.04 with PHP v7.2.
The text was updated successfully, but these errors were encountered: