PHP incorrectly closes file handles when used to replace STDIN/STDOUT/STDERR
オープン
まだ誰も着手していません。
Category: Streams
Feature
SAPI: cli
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.1k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず Debian 11 上で PHP 8.2.6 の例を再現し、STDIN、STDOUT、STDERR の置き換えと、その後のガベージコレクションに焦点を当てます。exec が実行される前に、これらの標準ストリームがどのように扱われるかを追跡します。置き換え用のハンドルがグローバル変数に保持されていない場合でも、コマンドが戻りコード 134 で失敗しなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- operating-systems
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100