PHP incorrectly closes file handles when used to replace STDIN/STDOUT/STDERR
未关闭
还没有人认领这个 Issue。
Category: Streams
Feature
SAPI: cli
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
The following code:
<?php
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
fopen('/dev/null', 'r');
fopen('/dev/null', 'w');
fopen('/dev/null', 'w');
exec("dig +noall +answer -t ns -q 'www.google.com'", $out, $ret);
file_put_contents('ret.txt', $ret . "\n");
Resulted in exec failing with the return code 134 as seen in ret.txt
PHP's garbage collection seems to have not taken into account that the file handles opened are now in use as stdin/stdout/stderr. Obviously this can be worked around by storing the result of fopen into some global vars, but IMO this is a bug.
PHP Version
PHP 8.2.6
Operating System
Debian 11
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 Debian 11 上重现 PHP 8.2.6 示例,重点关注 STDIN、STDOUT 和 STDERR 的替换以及后续的垃圾回收。跟踪 exec 运行前这些标准流的处理方式。当替换句柄未保存在全局变量中时,该命令不再以返回码 134 失败,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100