#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stdarg.h>
#include <process.h>
#include "service.h"
/* 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
*/
#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); \
}
} \
}
+/*
+ * 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)
{
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)
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);