--- parser3/src/main/pa_exec.C 2003/03/26 18:52:50 1.48.2.18.2.11 +++ parser3/src/main/pa_exec.C 2003/07/22 08:19:58 1.48.2.18.2.17 @@ -7,7 +7,7 @@ @todo setrlimit */ -static const char* IDENT_EXEC_C="$Date: 2003/03/26 18:52:50 $"; +static const char* IDENT_EXEC_C="$Date: 2003/07/22 08:19:58 $"; #include "pa_config_includes.h" @@ -33,91 +33,92 @@ static DWORD CreateHiddenConsoleProcess( LPHANDLE phOutRead, LPHANDLE phErrRead) { - DWORD result=0; + DWORD result=0; BOOL fCreated; - STARTUPINFO si; - SECURITY_ATTRIBUTES sa={0}; - HANDLE hInRead; - HANDLE hOutWrite; - HANDLE hErrWrite; - - // Create pipes - // initialize security attributes for handle inheritance (for WinNT) - sa.nLength=sizeof(sa); - sa.bInheritHandle=TRUE; - sa.lpSecurityDescriptor=NULL; - - // create STDIN pipe - if(!CreatePipe(&hInRead, phInWrite, &sa, 0)) - goto error; - - // create STDOUT pipe - if(!CreatePipe(phOutRead, &hOutWrite, &sa, 0)) - goto error; - - // create STDERR pipe - if(!CreatePipe(phErrRead, &hErrWrite, &sa, 0)) - goto error; - - // process startup information - memset(&si, 0, sizeof(si)); - si.cb=sizeof(si); - si.dwFlags=STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; - // child process' console must be hidden for Win95 compatibility - si.wShowWindow=SW_HIDE; - // assign "other" sides of pipes - si.hStdInput=hInRead; - si.hStdOutput=hOutWrite; - si.hStdError=hErrWrite; - + STARTUPINFO si; + SECURITY_ATTRIBUTES sa={0}; + HANDLE hInRead; + HANDLE hOutWrite; + HANDLE hErrWrite; + + // Create pipes + // initialize security attributes for handle inheritance (for WinNT) + sa.nLength=sizeof(sa); + sa.bInheritHandle=TRUE; + sa.lpSecurityDescriptor=NULL; + + // create STDIN pipe + if(!CreatePipe(&hInRead, phInWrite, &sa, 0)) + goto error; + + // create STDOUT pipe + if(!CreatePipe(phOutRead, &hOutWrite, &sa, 0)) + goto error; + + // create STDERR pipe + if(!CreatePipe(phErrRead, &hErrWrite, &sa, 0)) + goto error; + + // process startup information + memset(&si, 0, sizeof(si)); + si.cb=sizeof(si); + si.dwFlags=STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; + // child process' console must be hidden for Win95 compatibility + si.wShowWindow=SW_HIDE; + // assign "other" sides of pipes + si.hStdInput=hInRead; + si.hStdOutput=hOutWrite; + si.hStdError=hErrWrite; + // calculating script's directory char dir[MAX_STRING]; strncpy(dir, szCmdLine, MAX_STRING-1); dir[MAX_STRING-1]=0; lsplit(dir,' '); // trim arguments rsplit(dir,'/'); rsplit(dir,'\\'); // trim filename chdir(dir); - - // Create a child process (suspended) - fCreated=CreateProcess(NULL, - (LPTSTR)szCmdLine, - NULL, - NULL, - TRUE, - CREATE_NO_WINDOW, - szEnv, - dir, - &si, - ppi); + + // Create a child process (suspended) + fCreated=CreateProcess(NULL, + (LPTSTR)szCmdLine, + NULL, + NULL, + TRUE, + CREATE_NO_WINDOW, + szEnv, + dir, + &si, + ppi); if(!fCreated) result=GetLastError(); - - CloseHandle(hInRead); - CloseHandle(hOutWrite); - CloseHandle(hErrWrite); - - if(!fCreated) - goto error; - - return result; - + + CloseHandle(hInRead); + CloseHandle(hOutWrite); + CloseHandle(hErrWrite); + + if(!fCreated) + goto error; + + return result; + error: if(!result/*yet*/) result=GetLastError(); // get it - - CloseHandle(*phInWrite); - CloseHandle(*phOutRead); - CloseHandle(*phErrRead); - - return result; + + CloseHandle(*phInWrite); + CloseHandle(*phOutRead); + CloseHandle(*phErrRead); + + return result; } static void read_pipe(String& result, HANDLE hOutRead, String::Language lang){ while(true) { char *buf=new(PointerFreeGC) char[MAX_STRING]; unsigned long size; - if(!ReadFile(hOutRead, buf, MAX_STRING, &size, NULL) || !size) + if(!ReadFile(hOutRead, buf, MAX_STRING-1, &size, NULL) || !size) break; - result.append(buf, size, lang); + buf[size]=0; + result.append_know_length(buf, size, lang); } } @@ -134,7 +135,7 @@ static const char* buildCommand(const ch if(*begin==' ') // alx: were an old magic for some linux-es begin++; if(char *end=strchr(begin, '\n')) { - String string(begin, end-begin); + String string(pa_strdup(begin, end-begin)); string << " " << file_spec_cstr; result=string.cstr(); } @@ -279,10 +280,11 @@ static int get_exit_status(int pid) { static void read_pipe(String& result, int file, String::Language lang){ while(true) { char *buf=new(PointerFreeGC) char[MAX_STRING]; - ssize_t size=read(file, buf, MAX_STRING); - if(size<=0) + ssize_t length=read(file, buf, MAX_STRING-1); + if(length<=0) break; - result.append(buf, size, lang); + buf[length]=0; + result.append_know_length(buf, length, lang); } } @@ -303,7 +305,7 @@ static void append_env_pair(HashStringSt Append_env_pair_info *info) { #ifdef WIN32 info->string << key << "=" << value; - info->string.append("", 1, String::L_AS_IS); // zero byte + info->string.append_know_length("\1", 1, String::L_AS_IS); // placeholder for of zero byte #else StringBody body; body << key << "=" << value; @@ -341,6 +343,9 @@ PA_exec_result pa_exec( Append_env_pair_info info(string); env->for_each(append_env_pair, &info); env_cstr=info.string.cstrm(String::L_UNSPECIFIED); + for(char* replacer=env_cstr; *replacer; replacer++) + if(*replacer=='\1') + *replacer=0; } if(DWORD error=CreateHiddenConsoleProcess(cmd, env_cstr, &pi, &hInWrite, &hOutRead, &hErrRead)) { char szErrorDesc[MAX_STRING]; @@ -392,12 +397,7 @@ from http://www.apache.org/websrc/cvsweb "stat failed: %s (%d), actual filename '%s'", strerror(errno), errno, file_spec_cstr); - if(finfo.st_uid/*foreign?*/!=geteuid() - && finfo.st_gid/*foreign?*/!=getegid()) - throw Exception("parser.runtime", - &file_spec, - "parser is in safe mode: executing files of foreign group and user disabled [recompile parser with --disable-safe-mode configure option], actual filename '%s'", - file_spec_cstr); + check_safe_mode(finfo, file_spec, file_spec_cstr); } #endif