diff options
Diffstat (limited to 'service-win32')
-rwxr-xr-x | service-win32/openvpnserv.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/service-win32/openvpnserv.c b/service-win32/openvpnserv.c index b5d8d37..5b0eb6e 100755 --- a/service-win32/openvpnserv.c +++ b/service-win32/openvpnserv.c @@ -37,6 +37,7 @@ #include <windows.h> #include <stdlib.h> #include <stdio.h> +#include <stdarg.h> #include <process.h> #include "service.h" @@ -79,13 +80,6 @@ static HANDLE exit_event = NULL; /* clear an object */ #define CLEAR(x) memset(&(x), 0, sizeof(x)) -/* snprintf with guaranteed null termination */ -#define mysnprintf(out, ...) \ - { \ - _snprintf (out, sizeof(out), __VA_ARGS__); \ - out [sizeof (out) - 1] = '\0'; \ - } - /* * Message handling */ @@ -97,7 +91,7 @@ static HANDLE exit_event = NULL; #define MSG(flags, ...) \ { \ char x_msg[256]; \ - mysnprintf (x_msg, __VA_ARGS__); \ + openvpn_snprintf (x_msg, sizeof(x_msg), __VA_ARGS__); \ AddToMessageLog ((flags), x_msg); \ } @@ -129,6 +123,28 @@ static HANDLE exit_event = NULL; } \ } +/* + * This is necessary due to certain buggy implementations of snprintf, + * that don't guarantee null termination for size > 0. + * (copied from ../buffer.c, line 217) + * (git: 100644 blob e2f8caab0a5b2a870092c6cd508a1a50c21c3ba3 buffer.c) + */ + +int openvpn_snprintf(char *str, size_t size, const char *format, ...) +{ + va_list arglist; + int ret = 0; + if (size > 0) + { + va_start (arglist, format); + ret = vsnprintf (str, size, format, arglist); + va_end (arglist); + str[size - 1] = 0; + } + return ret; +} + + bool init_security_attributes_allow_all (struct security_attributes *obj) { @@ -353,7 +369,7 @@ VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) BOOL more_files; char find_string[MAX_PATH]; - mysnprintf (find_string, "%s\\*", config_dir); + openvpn_snprintf (find_string, MAX_PATH, "%s\\*", config_dir); find_handle = FindFirstFile (find_string, &find_obj); if (find_handle == INVALID_HANDLE_VALUE) @@ -395,10 +411,11 @@ VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) FindClose (find_handle); goto finish; } - mysnprintf (log_path, "%s\\%s", log_dir, log_file); + openvpn_snprintf (log_path, sizeof(log_path), + "%s\\%s", log_dir, log_file); /* construct command line */ - mysnprintf (command_line, PACKAGE " --service %s 1 --config \"%s\"", + openvpn_snprintf (command_line, sizeof(command_line), PACKAGE " --service %s 1 --config \"%s\"", EXIT_EVENT_NAME, find_obj.cFileName); |