From 469a2633569df35d86bb2b458267460e365b42df Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Tue, 22 Oct 2013 18:07:28 +0000 Subject: [PATCH] fixed: error when installing, The parameter is incorrect. --- src/lib/arch/CArchDaemonWindows.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/lib/arch/CArchDaemonWindows.cpp b/src/lib/arch/CArchDaemonWindows.cpp index ac25bfc1..7884b2e8 100644 --- a/src/lib/arch/CArchDaemonWindows.cpp +++ b/src/lib/arch/CArchDaemonWindows.cpp @@ -21,6 +21,7 @@ #include "CArchMiscWindows.h" #include "XArchWindows.h" #include "stdvector.h" +#include // // CArchDaemonWindows @@ -817,22 +818,15 @@ CArchDaemonWindows::installDaemon() // install default daemon if not already installed. if (!isDaemonInstalled(DEFAULT_DAEMON_NAME, true)) { char path[MAX_PATH]; - GetModuleFileName(CArchMiscWindows::instanceWin32(), &path[1], MAX_PATH - 2); - - int length = 0; - for (int i = 0; i < MAX_PATH; i++) { - if (path[i] == '\0') { - length = i; - break; - } - } + GetModuleFileName(CArchMiscWindows::instanceWin32(), path, MAX_PATH); // wrap in quotes so a malicious user can't start \Program.exe as admin. - path[0] = '"'; - path[length] = '"'; - path[length + 1] = '\0'; + std::stringstream ss; + ss << '"'; + ss << path; + ss << '"'; - installDaemon(DEFAULT_DAEMON_NAME, DEFAULT_DAEMON_INFO, path, "", "", true); + installDaemon(DEFAULT_DAEMON_NAME, DEFAULT_DAEMON_INFO, ss.str().c_str(), "", "", true); } start(DEFAULT_DAEMON_NAME);