--- parser3/src/main/pa_exec.C 2003/03/24 13:16:12 1.48.2.18.2.8 +++ parser3/src/main/pa_exec.C 2003/04/08 12:47:31 1.48.2.18.2.15 @@ -7,7 +7,7 @@ @todo setrlimit */ -static const char* IDENT_EXEC_C="$Date: 2003/03/24 13:16:12 $"; +static const char* IDENT_EXEC_C="$Date: 2003/04/08 12:47:31 $"; #include "pa_config_includes.h" @@ -115,9 +115,10 @@ static void read_pipe(String& result, HA 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); } } @@ -148,7 +149,7 @@ static const char* buildCommand(const ch } { // appending argv String string(result); - for(int i=0; istring << key << "=" << value; - info->string.append("", 1, String::L_AS_IS); // zero byte + info->string.append_know_length("", 1, String::L_AS_IS); // zero byte #else - String string; - string << key << "=" << *value; + StringBody body; + body << key << "=" << value; - *(info->env_ref++)=string.cstr(*info->String::L_UNSPECIFIED); + *(info->env_ref++)=body.cstrm(); #endif } @@ -328,7 +330,8 @@ PA_exec_result pa_exec( "parser execs are disabled [recompile parser without --disable-execs configure option]"); #endif - const char* file_spec_cstr=file_spec.cstr(String::L_FILE_SPEC); + // execve needs non const + char* file_spec_cstr=file_spec.cstrm(String::L_FILE_SPEC); #ifdef WIN32 PROCESS_INFORMATION pi; @@ -387,34 +390,29 @@ from http://www.apache.org/websrc/cvsweb struct stat finfo; if(stat(file_spec_cstr, &finfo)!=0) throw Exception("file.missing", - file_spec, - "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); + &file_spec, + "stat failed: %s (%d), actual filename '%s'", + strerror(errno), errno, file_spec_cstr); + + check_safe_mode(finfo, file_spec, file_spec_cstr); } #endif - char * argv_cstrs[1+10+1]={file_spec_cstr, 0}; + char* argv_cstrs[1+10+1]={file_spec_cstr, 0}; const int argv_size=argv.count(); const int argv_max=sizeof(argv_cstrs)/sizeof(argv_cstrs[0])-1-1; if(argv_size>argv_max) throw Exception("parser.runtime", - file_spec, + &file_spec, "too many arguments (%d > max %d)", argv_size, argv_max); for(int i=0; icstr(); + argv_cstrs[1+i]=argv[i]->cstrm(); argv_cstrs[1+argv_size]=0; char **env_cstrs; if(env) { - env_cstrs=new char *[env->count()+1/*0*/]; - Append_env_pair_info info={&env_cstrs}; + env_cstrs=new(PointerFreeGC) char *[env->count()+1/*0*/]; + Append_env_pair_info info={env_cstrs}; env->for_each(append_env_pair, &info); *info.env_ref=0; } else @@ -431,15 +429,15 @@ from http://www.apache.org/websrc/cvsweb write(pipe_write, in_cstr, in.length()); } close(pipe_write); - result.out=read_pipe(pipe_read, file_spec_cstr, String::L_AS_IS); + read_pipe(result.out, pipe_read, String::L_AS_IS); close(pipe_read); - result.err=read_pipe(pipe_err, file_spec_cstr, String::L_TAINTED); + read_pipe(result.err, pipe_err, String::L_TAINTED); close(pipe_err); result.status=get_exit_status(pid); // negative may mean "-errno[execl()]" } else throw Exception(0, - file_spec, + &file_spec, "%s error: %s (%d)", pid<0?"fork":"pipe", strerror(errno), errno); #endif