RE: [PHP-CVS] com php-src: Fixed bug #71039 exec functions ignore length but look for NULL termination: ext/standard/exec.c
ext/standard/tests/general_functions/escapeshellarg_bug71039.phpt ext/standard/tests/general_functions/escapeshellcmd_bug71039.phpt

From: Date: Tue, 02 Feb 2016 14:13:48 +0000
Subject: RE: [PHP-CVS] com php-src: Fixed bug #71039 exec functions ignore length but look for NULL termination: ext/standard/exec.c
ext/standard/tests/general_functions/escapeshellarg_bug71039.phpt ext/standard/tests/general_functions/escapeshellcmd_bug71039.phpt
References: 1 2  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-90906@lists.php.net to get a copy of this message
Hi Yasuo, > -----Original Message----- > From: yohgaki@gmail.com [mailto:yohgaki@gmail.com] On Behalf Of Yasuo > Ohgaki > Sent: Tuesday, February 2, 2016 2:09 PM > To: Stanislav Malyshev <stas@php.net> > Cc: php-cvs@lists.php.net > Subject: Re: [PHP-CVS] com php-src: Fixed bug #71039 exec functions ignore > length but look for NULL termination: ext/standard/exec.c > ext/standard/tests/general_functions/escapeshellarg_bug71039.phpt > ext/standard/tests/general_functions/escapeshellcmd_bug71039.phpt > > Hi Stas, > > It's seems patch by Anatol, but anyway > > On Tue, Jan 12, 2016 at 10:57 PM, Stanislav Malyshev <stas@php.net> wrote: > > Diff: > > diff --git a/ext/standard/exec.c b/ext/standard/exec.c index > > 747f765..29024f6 100644 > > --- a/ext/standard/exec.c > > +++ b/ext/standard/exec.c > > @@ -467,6 +467,10 @@ PHP_FUNCTION(escapeshellcmd) > > } > > > > if (command_len) { > > + if (command_len != strlen(command)) { > > + php_error_docref(NULL, E_ERROR, "Input string contains NULL > bytes"); > > + return; > > + } > > RETVAL_STR(php_escape_shell_cmd(command)); > > } else { > > RETVAL_EMPTY_STRING(); @@ -486,6 +490,10 @@ > > PHP_FUNCTION(escapeshellarg) > > } > > > > if (argument) { > > + if (argument_len != strlen(argument)) { > > + php_error_docref(NULL, E_ERROR, "Input string contains NULL > bytes"); > > + return; > > + } > > RETVAL_STR(php_escape_shell_arg(argument)); > > } > > } > > These are escape functions. User shouldn't use esacapeshellcmd() for external > inputs, but escapeshellarg() will be. The error should be > E_RECOVERABLE_ERROR or E_WARNING, so that user can handle errors. > Warning and empty string would be enough, IMO. > Thanks for the comments. The decision for failing hard here was, that we don't really can't evaluate what to do. If you look at the initial issue in the ticket, passing string "bad\0worse" can be dangerous as internally we don't know what is safe - fe to stop parsing at \0, or to glue the both parts together, or whatever. Yeah, external inputs are dangerous and we cannot prevent anyone to accept them. So E_WARNING were a nogo. E_RECOVERABLE_ERROR (or an exception somewhen) could come into question, just such invalid inputs are actually an unusual case and again some situation that cannot be evaluated, so it was decided just for more safety. As what happens if user catches the error and has an empty sting that is expected to build a composite command (which possibly could build some erroneous dangerous command)? Another discussion about this happened also in #71270. Regards Anatol

« previous php.cvs (#90906) next »