@@ -507,6 +507,28 @@ static void init_startup_info(STARTUPINFOW *si, struct php_proc_open_descriptor_
507
507
}
508
508
}
509
509
}
510
+
511
+ static int convert_command_to_use_shell (wchar_t * * cmdw , size_t cmdw_len )
512
+ {
513
+ size_t len = sizeof (COMSPEC_NT ) + sizeof (" /s /c " ) + cmdw_len + 3 ;
514
+ wchar_t * cmdw_shell = (wchar_t * )malloc (len * sizeof (wchar_t ));
515
+
516
+ if (cmdw_shell == NULL ) {
517
+ php_error_docref (NULL , E_WARNING , "Command conversion failed" );
518
+ return FAILURE ;
519
+ }
520
+
521
+ if (_snwprintf (cmdw_shell , len , L"%hs /s /c \"%s\"" , COMSPEC_NT , * cmdw ) == -1 ) {
522
+ free (cmdw_shell );
523
+ php_error_docref (NULL , E_WARNING , "Command conversion failed" );
524
+ return FAILURE ;
525
+ }
526
+
527
+ free (* cmdw );
528
+ * cmdw = cmdw_shell ;
529
+
530
+ return SUCCESS ;
531
+ }
510
532
#endif
511
533
512
534
static struct php_proc_open_descriptor_item * alloc_descriptor_array (zval * descriptorspec )
@@ -650,7 +672,7 @@ PHP_FUNCTION(proc_open)
650
672
UINT old_error_mode ;
651
673
char cur_cwd [MAXPATHLEN ];
652
674
wchar_t * cmdw = NULL , * cwdw = NULL , * envpw = NULL ;
653
- size_t tmp_len ;
675
+ size_t cmdw_len ;
654
676
int suppress_errors = 0 ;
655
677
int bypass_shell = 0 ;
656
678
int blocking_pipes = 0 ;
@@ -968,39 +990,19 @@ PHP_FUNCTION(proc_open)
968
990
}
969
991
}
970
992
971
- cmdw = php_win32_cp_conv_any_to_w (command , strlen (command ), & tmp_len );
993
+ cmdw = php_win32_cp_conv_any_to_w (command , strlen (command ), & cmdw_len );
972
994
if (!cmdw ) {
973
995
php_error_docref (NULL , E_WARNING , "Command conversion failed" );
974
996
goto exit_fail ;
975
997
}
976
998
977
- if (bypass_shell ) {
978
- newprocok = CreateProcessW (NULL , cmdw , & php_proc_open_security , & php_proc_open_security ,
979
- TRUE, dwCreateFlags , envpw , cwdw , & si , & pi );
980
- } else {
981
- int ret ;
982
- size_t len ;
983
- wchar_t * cmdw2 ;
984
-
985
-
986
- len = (sizeof (COMSPEC_NT ) + sizeof (" /s /c " ) + tmp_len + 3 );
987
- cmdw2 = (wchar_t * )malloc (len * sizeof (wchar_t ));
988
- if (!cmdw2 ) {
989
- php_error_docref (NULL , E_WARNING , "Command conversion failed" );
999
+ if (!bypass_shell ) {
1000
+ if (convert_command_to_use_shell (& cmdw , cmdw_len ) == FAILURE ) {
990
1001
goto exit_fail ;
991
1002
}
992
- ret = _snwprintf (cmdw2 , len , L"%hs /s /c \"%s\"" , COMSPEC_NT , cmdw );
993
-
994
- if (-1 == ret ) {
995
- free (cmdw2 );
996
- php_error_docref (NULL , E_WARNING , "Command conversion failed" );
997
- goto exit_fail ;
998
- }
999
-
1000
- newprocok = CreateProcessW (NULL , cmdw2 , & php_proc_open_security , & php_proc_open_security ,
1001
- TRUE, dwCreateFlags , envpw , cwdw , & si , & pi );
1002
- free (cmdw2 );
1003
1003
}
1004
+ newprocok = CreateProcessW (NULL , cmdw , & php_proc_open_security , & php_proc_open_security ,
1005
+ TRUE, dwCreateFlags , envpw , cwdw , & si , & pi );
1004
1006
1005
1007
free (cwdw );
1006
1008
cwdw = NULL ;
0 commit comments