Skip to content

Stdlib: system()/passthru() bypass active output buffer — ob_get_clean() empty (ext/standard/exec.c) #10492

Description

@PurHur

Category

stdlib — shell exec + output buffering

Problem

With an active ob_start() buffer, system() and passthru() must route command stdout into the buffer (Zend does not echo to real stdout). This compiler echoes directly; ob_get_clean() returns an empty string while Zend captures 'hi\n'.

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/maintainer_gap_system_ob_capture.php'
# VM stdout leaks "hi" + var_export([\"hi\", \"\"]); Zend: var_export([\"hi\", \"hi\\n\"]) only
Call Zend ob_get_clean() This compiler
ob_start(); system('echo hi'); 'hi\n' '' (plus leaked stdout)
ob_start(); passthru('echo hi'); 'hi\n' '' (plus leaked stdout)
exec('echo hi', $out, $code) populates $out populates $out

php-src reference

Repro

<?php
ob_start();
$r = system('echo hi');
$o = ob_get_clean();
var_export([$r, $o]); // Zend: ['hi', "hi\n"]; VM: ['hi', '']

Committed repro: test/repro/maintainer_gap_system_ob_capture.php.

Scope (PHP-in-PHP)

Path Work
ext/standard/VmExec.php (or equivalent) Route system()/passthru() stdout through OB layer / VmOb
ext/standard/VmOb.php Ensure shell builtins use same write path as echo

Prefer PHP OB integration — no new C exec output path.

Done when (php-src-strict)

  • ob_start(); system('echo hi'); ob_get_clean() captures full command output (no stdout leak)
  • Same for passthru()
  • Return value semantics unchanged (system last line, passthru NULL)
  • ./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_system_ob_capture.php' matches Zend (no extra stdout)
  • Unit/compliance guard under test/compliance/ or test/unit/

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions