Diff for /parser3/src/main/pa_exec.C between versions 1.90 and 1.99

version 1.90, 2016/12/24 23:07:50 version 1.99, 2024/11/24 15:37:10
Line 1 Line 1
 /** @file  /** @file
         Parser: program executing for different OS-es.          Parser: program executing for different OS-es.
   
         Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com)          Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
   
         @todo setrlimit          @todo setrlimit
 */  */
Line 79  static DWORD CreateHiddenConsoleProcess( Line 79  static DWORD CreateHiddenConsoleProcess(
                   
         // calculating script's directory          // calculating script's directory
         char dir[MAX_STRING];          char dir[MAX_STRING];
         strncpy(dir, szScriptFileSpec, MAX_STRING-1); dir[MAX_STRING-1]=0;          pa_strncpy(dir, szScriptFileSpec, MAX_STRING);
         lsplit(dir,' '); // trim arguments          lsplit(dir,' '); // trim arguments
         rsplit(dir,'/'); rsplit(dir,'\\'); // trim filename          rsplit(dir,'/'); rsplit(dir,'\\'); // trim filename
                   
Line 165  static void read_pipe(File_read_result& Line 165  static void read_pipe(File_read_result&
         }          }
 }  }
   
   static const char* shell_quote(const char *arg) {
           size_t length = strlen(arg);
           if (length >= 2 && arg[0] == '"' && arg[length - 1] == '"')
                   return arg; // allready qouted
   
           size_t extra_length = 2; // opening and closing quotes
           for(const char *src = arg; *src; src++){
                   if (*src == '"' || *src == '\\' || *src == '%')
                           extra_length++;
           }
   
           char *result = (char *)pa_malloc(length + extra_length + 1);
           char *dest = result;
   
           *dest++ = '"';
   
           for(const char *src=arg; *src;){
                   char c = *src++;
                   if(c == '"' || c == '\\'){
                           *dest++ = '\\';
                   } else if (c == '%'){
                           *dest++ = '%'; // doubling '%'
                   }
                   *dest++ = c;
           }
   
           *dest++ = '"';
           *dest = '\0';
           return result;
   }
   
 static const char* buildCommand(const char* file_spec_cstr, const ArrayString& argv) {  static const char* buildCommand(const char* file_spec_cstr, const ArrayString& argv) {
         const char* result=file_spec_cstr;          const char* result=file_spec_cstr;
         if(FILE *f=fopen(file_spec_cstr, "r")) {          if(FILE *f=pa_fopen(file_spec_cstr, "r")) {
                 try {                  try {
                 char buf[MAX_STRING];                  char buf[MAX_STRING];
                 size_t size=fread(buf, 1, MAX_STRING-1, f);                  size_t size=fread(buf, 1, MAX_STRING-1, f);
Line 194  static const char* buildCommand(const ch Line 225  static const char* buildCommand(const ch
                 String string(result);                  String string(result);
                 for(size_t i=0; i<argv.count(); i++) {                  for(size_t i=0; i<argv.count(); i++) {
                         string << " ";                          string << " ";
                         string << *argv[i];                          string << shell_quote(argv[i]->cstr());
                 }                  }
   
                 result=string.cstr();                  result=string.cstr();
Line 283  static pid_t execve_piped(const char* fi Line 314  static pid_t execve_piped(const char* fi
                   
                 // chdir to script's directory                  // chdir to script's directory
                 char dir[MAX_STRING];                  char dir[MAX_STRING];
                 strncpy(dir, file_spec_cstr, MAX_STRING-1); dir[MAX_STRING-1]=0;                  pa_strncpy(dir, file_spec_cstr, MAX_STRING);
                 rsplit(dir,'/'); // trim filename                  rsplit(dir,'/'); // trim filename
                 chdir(dir);                  chdir(dir);
   
Line 313  static pid_t execve_piped(const char* fi Line 344  static pid_t execve_piped(const char* fi
 }  }
   
 static int get_exit_status(int pid) {  static int get_exit_status(int pid) {
         int status;          int status=0;
         pid_t cid;          pid_t cid;
         while ((cid=waitpid(pid, &status, WUNTRACED)) == -1 && errno == EINTR);           while ((cid=waitpid(pid, &status, WUNTRACED)) == -1 && errno == EINTR); 
         if(!cid)          if(!cid)
Line 368  struct Append_env_pair_info { Line 399  struct Append_env_pair_info {
 };  };
 #endif  #endif
   
 ///@test maybe here and at argv construction --- untaint_cstr(String::L_AS_IS  
 static void append_env_pair(HashStringString::key_type key, HashStringString::value_type value,  static void append_env_pair(HashStringString::key_type key, HashStringString::value_type value,
                 Append_env_pair_info *info) {                  Append_env_pair_info *info) {
 #ifdef _MSC_VER  #ifdef _MSC_VER
Line 442  PA_exec_result pa_exec(bool forced_allow Line 472  PA_exec_result pa_exec(bool forced_allow
   
         if(!forced_allow) {          if(!forced_allow) {
                 struct stat finfo;                  struct stat finfo;
                 if(stat(file_spec_cstr, &finfo)!=0)                  if(pa_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);                          throw Exception("file.missing", &file_spec, "stat failed: %s (%d), actual filename '%s'", strerror(errno), errno, file_spec_cstr);
   
                 check_safe_mode(finfo, file_spec, file_spec_cstr);                  check_safe_mode(finfo, file_spec, file_spec_cstr);

Removed from v.1.90  
changed lines
  Added in v.1.99


E-mail: