所有EXEC相关的PHP函数段错误 [英] all exec related PHP functions segfault
问题描述
我建立PHP使用NDK的Android。到目前为止测试的完美运行,除非......大多数功能
I build PHP for android using the NDK. Most functions tested so far run perfectly, except...
所有EXEC相关的PHP函数(象exec,了shell_exec,popen这,..)所有sefgault。
All exec related php function (like exec, shell_exec, popen, ..) all sefgault.
PHP示例code(test.php的)
php sample code (test.php)
<?php
$s=shell_exec("ls");
echo $s
?>
结果:
# php test.php
[1] Segmentation fault
我加了一些调试code到内部功能了shell_exec
I added some debug code to the internal shell_exec function
PHP_FUNCTION(shell_exec)
{
FILE *in;
size_t total_readbytes;
zval **cmd;
char *ret;
php_stream *stream;
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &cmd)==FAILURE) {
WRONG_PARAM_COUNT;
}
if (PG(safe_mode)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot execute using backquotes in Safe Mode");
RETURN_FALSE;
}
convert_to_string_ex(cmd);
#ifdef PHP_WIN32
if ((in=VCWD_POPEN(Z_STRVAL_PP(cmd), "rt"))==NULL) {
#else
if ((in=VCWD_POPEN(Z_STRVAL_PP(cmd), "r"))==NULL) {
#endif
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute '%s'", Z_STRVAL_PP(cmd));
RETURN_FALSE;
}
stream = php_stream_fopen_from_pipe(in, "rb");
total_readbytes = php_stream_copy_to_mem(stream, &ret, PHP_STREAM_COPY_ALL, 0);
php_stream_close(stream);
printf("TEST\n%s\n",ret);
if (total_readbytes > 0) {
RETURN_STRINGL(ret, total_readbytes, 0);
} else {
RETURN_NULL();
}
}
结果
# php test.php
TEST
test.php
[1] Segmentation fault
我的结论
结果 - LS的EXEC工作正常
结果 - 在LS的结果是确定
I conclude
- the exec of ls is working fine
- the result of the ls is ok
不过某样东西是错误的。
Still something gets wrong.
问题1:
结果有人能指出我到执行PHP_FUNCTION(了shell_exec)在code部分,这样我就可以尝试看看一些更多的细节地方出错
Question 1:
Can someone point me to the code section where the PHP_FUNCTION(shell_exec) is executed, so i can try to see some more details of where it goes wrong
问题2:
结果是什么可能是错误的任何提示。
Question 2:
Any hints on what might be wrong.
版本信息
结果的Android 2.3.1
结果的Android NDK 6
结果PHP 5.2.17
Version info
Android 2.3.1
Android NDK 6
PHP 5.2.17
推荐答案
感谢名单给谁发电子邮件给我一些有用的提示匿名的。
Thanx to the anonymous who send me an email with some usefull tips.
事实证明PHP使用popen这对人的EXEC相关code。
A点可能知道机器人的popen的仿生版本是相当马车,直到ICS,这是知道的腐败堆栈。
As it turns out php uses popen for al its exec related code. A some might know androids bionic version of popen was quite buggy up until ICS and it is know the corrupt the stack.
我修改PHP使用的popen的修改优化版本
现在PHP的exec /等了shell_exec没有任何问题,都跑
I modified php to use a modified verion of popen Now php exec/shell_exec etc all run without any problems
这篇关于所有EXEC相关的PHP函数段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!