@@ -852,15 +852,17 @@ char **argv;
852
852
}
853
853
854
854
static struct ChildRecord *
855
- CreateChild (char * cmd , char * prog , SECURITY_ATTRIBUTES * psa , HANDLE hInput , HANDLE hOutput , HANDLE hError )
855
+ CreateChild (const char * cmd , const char * prog , SECURITY_ATTRIBUTES * psa ,
856
+ HANDLE hInput , HANDLE hOutput , HANDLE hError )
856
857
{
857
858
BOOL fRet ;
858
859
DWORD dwCreationFlags ;
859
860
STARTUPINFO aStartupInfo ;
860
861
PROCESS_INFORMATION aProcessInformation ;
861
862
SECURITY_ATTRIBUTES sa ;
862
- char * shell ;
863
+ const char * shell ;
863
864
struct ChildRecord * child ;
865
+ char * p = NULL ;
864
866
865
867
if (!cmd && !prog ) {
866
868
errno = EFAULT ;
@@ -908,7 +910,9 @@ CreateChild(char *cmd, char *prog, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HAND
908
910
dwCreationFlags = (NORMAL_PRIORITY_CLASS );
909
911
910
912
if (prog ) {
911
- shell = prog ;
913
+ if (!(p = dln_find_exe (prog , NULL ))) {
914
+ shell = prog ;
915
+ }
912
916
}
913
917
else {
914
918
int redir = -1 ;
@@ -938,15 +942,45 @@ CreateChild(char *cmd, char *prog, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HAND
938
942
cmd = tmp ;
939
943
}
940
944
else {
941
- char * tmp = ALLOCA_N (char , len + 1 );
942
- sprintf (tmp , "%.*s" , len , cmd );
943
- cmd = tmp ;
944
945
shell = NULL ;
946
+ prog = cmd ;
947
+ for (;;) {
948
+ if (!* prog ) {
949
+ p = dln_find_exe (cmd , NULL );
950
+ break ;
951
+ }
952
+ if (strchr (".:*?\"/\\" , * prog )) {
953
+ if (cmd [len ]) {
954
+ char * tmp = ALLOCA_N (char , len + 1 );
955
+ memcpy (tmp , cmd , len );
956
+ tmp [len ] = 0 ;
957
+ cmd = tmp ;
958
+ }
959
+ break ;
960
+ }
961
+ if (ISSPACE (* prog ) || strchr ("<>|" , * prog )) {
962
+ len = prog - cmd ;
963
+ p = ALLOCA_N (char , len + 1 );
964
+ memcpy (p , cmd , len );
965
+ p [len ] = 0 ;
966
+ p = dln_find_exe (p , NULL );
967
+ break ;
968
+ }
969
+ prog ++ ;
970
+ }
971
+ }
972
+ }
973
+ if (p ) {
974
+ shell = p ;
975
+ while (* p ) {
976
+ if ((unsigned char )* p == '/' )
977
+ * p = '\\' ;
978
+ p = CharNext (p );
945
979
}
946
980
}
947
981
948
982
RUBY_CRITICAL ({
949
- fRet = CreateProcess (shell , cmd , psa , psa ,
983
+ fRet = CreateProcess (shell , ( char * ) cmd , psa , psa ,
950
984
psa -> bInheritHandle , dwCreationFlags , NULL , NULL ,
951
985
& aStartupInfo , & aProcessInformation );
952
986
errno = map_errno (GetLastError ());
0 commit comments