aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorLRN <lrn1986@gmail.com>2013-04-21 13:36:59 +0000
committerLRN <lrn1986@gmail.com>2013-04-21 13:36:59 +0000
commit5ce430baaf7790495efd7b99cdcb3920fdb74218 (patch)
treebd6462ee6d08f54ebb2bd872f00a3371cf6008df /contrib
parent5eb44fbf35d9f0a332ced2b2d1f6defbf47206b5 (diff)
Use safer functions in w32 watchdog
Diffstat (limited to 'contrib')
-rw-r--r--contrib/timeout_watchdog_w32.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/contrib/timeout_watchdog_w32.c b/contrib/timeout_watchdog_w32.c
index 46a6157554..e136c03a8f 100644
--- a/contrib/timeout_watchdog_w32.c
+++ b/contrib/timeout_watchdog_w32.c
@@ -37,7 +37,6 @@ main (int argc, char *argv[])
wchar_t **wargv;
wchar_t *arg;
unsigned int cmdlen;
- wchar_t *idx;
STARTUPINFOW start;
PROCESS_INFORMATION proc;
@@ -50,6 +49,7 @@ main (int argc, char *argv[])
wchar_t *wcmd;
int wargc;
int timeout = 0;
+ ssize_t wrote;
HANDLE job;
@@ -125,22 +125,25 @@ main (int argc, char *argv[])
while (NULL != (arg = wargv[i++]))
cmdlen += wcslen (arg) + 4;
- wcmd = idx = malloc (sizeof (wchar_t) * (cmdlen + 1));
+ wcmd = malloc (sizeof (wchar_t) * (cmdlen + 1));
+ wrote = 0;
i = 2;
while (NULL != (arg = wargv[i++]))
{
/* This is to escape trailing slash */
wchar_t arg_lastchar = arg[wcslen (arg) - 1];
- if (idx == wcmd)
- idx += swprintf (idx, L"\"%s%s\" ", wpath,
+ if (wrote == 0)
+ {
+ wrote += _snwprintf (&wcmd[wrote], cmdlen + 1 - wrote, L"\"%s%s\" ", wpath,
arg_lastchar == L'\\' ? L"\\" : L"");
+ }
else
{
if (wcschr (arg, L' ') != NULL)
- idx += swprintf (idx, L"\"%s%s\"%s", arg,
+ wrote += swprintf (&wcmd[wrote], cmdlen + 1 - wrote, L"\"%s%s\"%s", arg,
arg_lastchar == L'\\' ? L"\\" : L"", i == wargc ? L"" : L" ");
else
- idx += swprintf (idx, L"%s%s%s", arg,
+ wrote += swprintf (&wcmd[wrote], cmdlen + 1 - wrote, L"%s%s%s", arg,
arg_lastchar == L'\\' ? L"\\" : L"", i == wargc ? L"" : L" ");
}
}