--- parser3/src/main/pa_exec.C 2024/11/24 15:37:10 1.99 +++ parser3/src/main/pa_exec.C 2024/12/24 02:58:47 1.104 @@ -13,7 +13,7 @@ #include "pa_exception.h" #include "pa_common.h" -volatile const char * IDENT_PA_EXEC_C="$Id: pa_exec.C,v 1.99 2024/11/24 15:37:10 moko Exp $" IDENT_PA_EXEC_H; +volatile const char * IDENT_PA_EXEC_C="$Id: pa_exec.C,v 1.104 2024/12/24 02:58:47 moko Exp $" IDENT_PA_EXEC_H; #ifdef _MSC_VER @@ -131,7 +131,7 @@ static int get_exit_status(HANDLE hProce return dwExitCode; } -static void read_pipe(String& result, HANDLE hOutRead, String::Language lang){ +static void read_pipe(String& result, HANDLE hOutRead, String::Language lang) { while(true) { char *buf=new(PointerFreeGC) char[MAX_STRING+1]; DWORD size=0; @@ -142,7 +142,7 @@ static void read_pipe(String& result, HA } } -static void read_pipe(File_read_result& result, HANDLE hOutRead){ +static void read_pipe(File_read_result& result, HANDLE hOutRead) { char *buf=(char*)pa_malloc(MAX_STRING+1); DWORD bufsize = MAX_STRING; @@ -165,14 +165,16 @@ static void read_pipe(File_read_result& } } -static const char* shell_quote(const char *arg) { +static const char* arg_quote(const char *arg) { size_t length = strlen(arg); + if (length >= 1 && arg[0] == '-') + return arg; // avoid options qouting 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 == '%') + if(*src == '"') extra_length++; } @@ -183,11 +185,8 @@ static const char* shell_quote(const cha for(const char *src=arg; *src;){ char c = *src++; - if(c == '"' || c == '\\'){ - *dest++ = '\\'; - } else if (c == '%'){ - *dest++ = '%'; // doubling '%' - } + if(c == '"') + *dest++ = '"'; *dest++ = c; } @@ -221,13 +220,13 @@ static const char* buildCommand(const ch } fclose(f); } + { // appending argv String string(result); for(size_t i=0; icstr()); + string << arg_quote(argv[i]->cstr()); } - result=string.cstr(); } @@ -316,7 +315,7 @@ static pid_t execve_piped(const char* fi char dir[MAX_STRING]; pa_strncpy(dir, file_spec_cstr, MAX_STRING); rsplit(dir,'/'); // trim filename - chdir(dir); + PA_UNUSED int ignore_result=chdir(dir); // execute execve(file_spec_cstr, argv, env); @@ -503,7 +502,7 @@ PA_exec_result pa_exec(bool forced_allow if(pid>0) { // in child if(in.length>0) // there is some in data - write(pipe_write, in.str, in.length); + PA_UNUSED int ignore_result=write(pipe_write, in.str, in.length); close(pipe_write); read_pipe(result.out, pipe_read); close(pipe_read);