From e9f02c9ea6e5a262005324fd0a3231ca39fa5c99 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 19 Jul 2021 13:33:51 +0200 Subject: [PATCH] MENT-1263 : ma_format_win32_error could cause invalid parameter exception If the formatted message was too long, for the buffer, sprintf_s used in this function raises invalid parameter. replace sprintf_s with snprintf to fix. --- libmariadb/win32_errmsg.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libmariadb/win32_errmsg.c b/libmariadb/win32_errmsg.c index eaa5872f..f890c4f6 100644 --- a/libmariadb/win32_errmsg.c +++ b/libmariadb/win32_errmsg.c @@ -117,7 +117,7 @@ void ma_format_win32_error(char* buf, size_t buflen, DWORD code, _Printf_format_ return; if (entry) { - sprintf_s(cur, end - cur, "%s. Error 0x%08lX(%s)", entry->msg, code, entry->sym); + snprintf(cur, end - cur, "%s. Error 0x%08lX(%s)", entry->msg, code, entry->sym); } else { @@ -131,7 +131,8 @@ void ma_format_win32_error(char* buf, size_t buflen, DWORD code, _Printf_format_ cur++; *cur = 0; } - sprintf_s(cur, end - cur, ". Error %lu/0x%08lX", code, code); + snprintf(cur, end - cur, ". Error %lu/0x%08lX", code, code); } + end[-1] = 0; }