From 1766fb0329d968ffe95cb650a4737843855b7cd0 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Mon, 3 Oct 2011 21:53:26 +0100 Subject: [PATCH] More CreateProcess() fun. Correctly handle the case where the application executable is under a path which contains space and an executable sharing the initial part of that path (up to a space) exists. A (contrived) example is when Application is C:\stuff\app lications\foo.exe and C:\stuff\app.exe also exists. Thanks Eugene Lifshitz. --- ChangeLog.txt | 8 ++++++++ README.txt | 1 + service.cpp | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 09d625e..b5ac32c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,11 @@ +Changes since 2.9 +----------------- + * Fixed edge case with CreateProcess(). + + Correctly handle the case where the application executable is under + a path which contains space and an executable sharing the initial + part of that path (up to a space) exists. + Changes since 2.8 ----------------- * Fixed failure to run on Windows versions prior to Vista. diff --git a/README.txt b/README.txt index 006b739..d609015 100644 --- a/README.txt +++ b/README.txt @@ -178,6 +178,7 @@ Thanks to Arve Knudsen for spotting that child processes of the monitored application could be left running on service shutdown, and that a missing registry value for AppDirectory confused NSSM. Thanks to Peter Wagemans and Laszlo Keresztfalvi for suggesting throttling restarts. +Thanks to Eugene Lifshitz for finding an edge case in CreateProcess(). Licence ------- diff --git a/service.cpp b/service.cpp index 60a8db0..4011484 100644 --- a/service.cpp +++ b/service.cpp @@ -308,7 +308,7 @@ int start_service() { /* Launch executable with arguments */ char cmd[CMD_LENGTH]; - if (_snprintf(cmd, sizeof(cmd), "%s %s", exe, flags) < 0) { + if (_snprintf(cmd, sizeof(cmd), "\"%s\" %s", exe, flags) < 0) { log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "command line", "start_service", 0); return stop_service(2, true, true); } -- 2.20.1