diff options
author | Sergey Zolotarev <sryze@protonmail.com> | 2021-01-31 19:41:29 +0600 |
---|---|---|
committer | Anel <an3l@users.noreply.github.com> | 2021-03-08 18:23:42 +0100 |
commit | d317350a76ecdacad4594b14d608455181bea2d9 (patch) | |
tree | 1479f96bcbc2026214f67475cb7fa2942074a78e /include | |
parent | 37546842a954c2bd17af0249ab6cb5f3f0d1ef37 (diff) | |
download | mariadb-git-d317350a76ecdacad4594b14d608455181bea2d9.tar.gz |
Remove trailing newline from error message in dlerror() on Windows
1. Add FORMAT_MESSAGE_MAX_WIDTH_MASK flag to remove trailing \r\n from
the error message returned by FormatMessageA().
2. Also, add FORMAT_MESSAGE_IGNORE_INSERTS to avoid potential problems
with system messages that have argument placeholders.
Quote from FormatMessage docs on MSDN:
If this function is called without FORMAT_MESSAGE_IGNORE_INSERTS, the
Arguments parameter must contain enough parameters to satisfy all insertion
sequences in the message string, and they must be of the correct type.
Therefore, do not use untrusted or unknown message strings with inserts
enabled because they can contain more insertion sequences than Arguments
provides, or those that may be of the wrong type. In particular, it is
unsafe to take an arbitrary system error code returned from an API and use
FORMAT_MESSAGE_FROM_SYSTEM without FORMAT_MESSAGE_IGNORE_INSERTS.
Diffstat (limited to 'include')
-rw-r--r-- | include/my_global.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/include/my_global.h b/include/my_global.h index da0d9920e06..e999e555bf7 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -1049,7 +1049,9 @@ typedef ulong myf; /* Type of MyFlags in my_funcs */ static inline char *dlerror(void) { static char win_errormsg[2048]; - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS + | FORMAT_MESSAGE_MAX_WIDTH_MASK, 0, GetLastError(), 0, win_errormsg, 2048, NULL); return win_errormsg; } |