@@ -199,31 +199,26 @@ PHPAPI int php_exec(int type, const char *cmd, zval *array, zval *return_value)
199199
200200static void php_exec_ex (INTERNAL_FUNCTION_PARAMETERS , int mode ) /* {{{ */
201201{
202- char * cmd ;
203- size_t cmd_len ;
202+ zend_string * cmd ;
204203 zval * ret_code = NULL , * ret_array = NULL ;
205204 int ret ;
206205
207206 ZEND_PARSE_PARAMETERS_START (1 , (mode ? 2 : 3 ))
208- Z_PARAM_STRING (cmd , cmd_len )
207+ Z_PARAM_PATH_STR (cmd )
209208 Z_PARAM_OPTIONAL
210209 if (!mode ) {
211210 Z_PARAM_ZVAL (ret_array )
212211 }
213212 Z_PARAM_ZVAL (ret_code )
214213 ZEND_PARSE_PARAMETERS_END ();
215214
216- if (! cmd_len ) {
215+ if (UNEXPECTED (! ZSTR_LEN ( cmd )) ) {
217216 zend_argument_must_not_be_empty_error (1 );
218217 RETURN_THROWS ();
219218 }
220- if (strlen (cmd ) != cmd_len ) {
221- zend_argument_value_error (1 , "must not contain any null bytes" );
222- RETURN_THROWS ();
223- }
224219
225220 if (!ret_array ) {
226- ret = php_exec (mode , cmd , NULL , return_value );
221+ ret = php_exec (mode , ZSTR_VAL ( cmd ) , NULL , return_value );
227222 } else {
228223 if (Z_TYPE_P (Z_REFVAL_P (ret_array )) == IS_ARRAY ) {
229224 ZVAL_DEREF (ret_array );
@@ -235,7 +230,7 @@ static void php_exec_ex(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
235230 }
236231 }
237232
238- ret = php_exec (2 , cmd , ret_array , return_value );
233+ ret = php_exec (2 , ZSTR_VAL ( cmd ) , ret_array , return_value );
239234 }
240235 if (ret_code ) {
241236 ZEND_TRY_ASSIGN_REF_LONG (ret_code , ret );
@@ -280,7 +275,7 @@ PHPAPI zend_string *php_escape_shell_cmd(const zend_string *unescaped_cmd)
280275 char * p = NULL ;
281276#endif
282277
283- ZEND_ASSERT (ZSTR_LEN (unescaped_cmd ) == strlen ( ZSTR_VAL ( unescaped_cmd ) ) && "Must be a binary safe string" );
278+ ZEND_ASSERT (! zend_str_has_nul_byte (unescaped_cmd ) && "Must be a binary safe string" );
284279 size_t l = ZSTR_LEN (unescaped_cmd );
285280 const char * str = ZSTR_VAL (unescaped_cmd );
286281
@@ -387,7 +382,7 @@ PHPAPI zend_string *php_escape_shell_arg(const zend_string *unescaped_arg)
387382 size_t x , y = 0 ;
388383 zend_string * cmd ;
389384
390- ZEND_ASSERT (ZSTR_LEN (unescaped_arg ) == strlen ( ZSTR_VAL ( unescaped_arg ) ) && "Must be a binary safe string" );
385+ ZEND_ASSERT (! zend_str_has_nul_byte (unescaped_arg ) && "Must be a binary safe string" );
391386 size_t l = ZSTR_LEN (unescaped_arg );
392387 const char * str = ZSTR_VAL (unescaped_arg );
393388
0 commit comments