Permalink
Browse files

Windows cf-upgrade: make re-execute command line construction more cl…

…ear.
  • Loading branch information...
1 parent 53e0afe commit 9cb071e80cb99d6dfe6c5f424e5aa2442a1d226a @jimis jimis committed Jul 16, 2014
Showing with 13 additions and 18 deletions.
  1. +13 −18 cf-upgrade/process.c
View
@@ -125,31 +125,24 @@ int private_run_process_wait(const char *command, char **args, char **envp)
* The Windows implementations were taken from Microsoft's documentation and
* modified accordingly to fit our purposes.
*/
-static void args_to_command_line(char **args, char *command_line)
+static void args_to_command_line(char *command_line, char **args,
+ unsigned long command_line_size)
{
/*
* Windows does not use an array for the command line arguments, but
* a string. Therefore we need to revert the parsing we did before and
* build the string.
*/
- char *p;
- int i;
- int current = 0;
- for (i = 0, p = args[0]; p; p = args[++i])
+ command_line[0] = '\0';
+ char *arg;
+ while ((arg = *args) != NULL)
{
- int j;
- for (j = 0; p[j] != '\0'; ++j)
- {
- command_line[current++] = p[j];
- }
+ strlcat(command_line, arg, command_line_size);
/* Add a space before the next argument */
- command_line[current++] = ' ';
+ strlcat(command_line, " ", command_line_size);
+
+ args++;
}
- /* We roll back to the last space that was added */
- current--;
- /* Make sure the command line is '\0' terminated */
- command_line[current] = '\0';
- return 0;
}
int private_run_process_replace(const char *command, char **args, char **envp)
@@ -163,7 +156,9 @@ int private_run_process_replace(const char *command, char **args, char **envp)
ZeroMemory( &pi, sizeof(pi) );
ZeroMemory( command_line, sizeof(command_line) );
- args_to_command_line(args, command_line);
+ args_to_command_line(command_line, args, sizeof(command_line));
+
+ log_entry(LogDebug, "Re-execute: %s", command_line);
// Start the child process.
if( !CreateProcess( command, // No module name (use command line)
@@ -208,7 +203,7 @@ int private_run_process_wait(const char *command, char **args, char **envp)
ZeroMemory( &pi, sizeof(pi) );
ZeroMemory( command_line, sizeof(command_line) );
- args_to_command_line(args, command_line);
+ args_to_command_line(command_line, args, sizeof(command_line));
// Start the child process.
if( !CreateProcess( command, // No module name (use command line)

0 comments on commit 9cb071e

Please sign in to comment.