From:             arekm at maven dot pl
Operating system: 
PHP version:      5.2.9
PHP Bug Type:     Feature/Change Request
Bug description:  upcoming apr closes descriptors by default

Description:
------------
Upcoming apr 2.0.0 (or 1.3 with backported patch) uses O_CLOEXEC for own
descriptors by default.

This means that when using shell_exec() the run script/binary has no
stdin/stdout/stderr due to O_CLOEXEC. This also means that if any output is
produced then script ends with EPIPE.

Tested with apache + apr 1.3 with backported patch.

http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?r1=747357&r2=748988



Reproduce code:
---------------
<?php
echo shell_exec("LC_ALL=C strace -o /tmp/WYNIK -f -F -s 200 ls -l
/notexistingfile");
?>

Run from apache + php + apr 1.3 + backported O_CLOEXEC patch like this one
http://cvs.pld-linux.org/cgi-bin/cvsweb/packages/apr/apr-bug-46425.patch?rev=1.8

Expected result:
----------------
run "ls -l" and produce some output about file not existing

Actual result:
--------------
30120 lstat("/notexistingfile", 0x18f55f0) = -1 ENOENT (No such file or
directory)
30120 write(2, "ls: ", 4)               = -1 EBADF (Bad file descriptor)
30120 write(2, "cannot access /notexistingfile", 30) = -1 EBADF (Bad file
descriptor)
30120 write(2, ": No such file or directory", 27) = -1 EBADF (Bad file
descriptor)
30120 write(2, "\n", 1)                 = -1 EBADF (Bad file descriptor)
30120 close(1)                          = 0
30120 close(2)                          = -1 EBADF (Bad file descriptor)
30120 exit_group(2)

As you can see there is no file descriptor 2 and this means that ls output
is lost.


Probably the best for php is to always provide own descriptors without
relying on apache provided one.           

-- 
Edit bug report at http://bugs.php.net/?id=48506&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=48506&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=48506&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=48506&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=48506&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=48506&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=48506&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=48506&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=48506&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=48506&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=48506&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=48506&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=48506&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=48506&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=48506&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48506&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48506&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=48506&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=48506&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=48506&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=48506&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=48506&r=mysqlcfg

Reply via email to