Commit d317350a authored by Sergey Zolotarev's avatar Sergey Zolotarev Committed by Anel

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.
parent 37546842
...@@ -1049,7 +1049,9 @@ typedef ulong myf; /* Type of MyFlags in my_funcs */ ...@@ -1049,7 +1049,9 @@ typedef ulong myf; /* Type of MyFlags in my_funcs */
static inline char *dlerror(void) static inline char *dlerror(void)
{ {
static char win_errormsg[2048]; 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); 0, GetLastError(), 0, win_errormsg, 2048, NULL);
return win_errormsg; return win_errormsg;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment