From 1cc2a892f247dd83c915a6d16317a5424d470476 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Fri, 10 Aug 2018 00:52:48 +0200 Subject: print_last_windows_error(): snprintf: undefined behavior if using variable as param and dest Signed-off-by: Toni Uhlig --- src/ptunnel.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ptunnel.c b/src/ptunnel.c index 7ac7ecb..c83ee24 100644 --- a/src/ptunnel.c +++ b/src/ptunnel.c @@ -63,11 +63,13 @@ /** Local error string storage */ static char errorstr[255]; static char * print_last_windows_error() { + char last_errorstr[255]; DWORD last_error = GetLastError(); - memset(errorstr, 0, sizeof(errorstr)); + + memset(last_errorstr, 0, sizeof(last_errorstr)); FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, last_error, 0, errorstr, sizeof(errorstr), NULL); - snprintf(errorstr, sizeof(errorstr), "%s (%lu)", errorstr, last_error); + NULL, last_error, 0, last_errorstr, sizeof(last_errorstr), NULL); + snprintf(errorstr, sizeof(errorstr), "%s (%lu)", last_errorstr, last_error); return errorstr; } #define strerror(x) print_last_windows_error() -- cgit v1.2.3