Skip to content

Commit d317350

Browse files
sryzean3l
authored andcommitted
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.
1 parent 3754684 commit d317350

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/my_global.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,9 @@ typedef ulong myf; /* Type of MyFlags in my_funcs */
10491049
static inline char *dlerror(void)
10501050
{
10511051
static char win_errormsg[2048];
1052-
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
1052+
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
1053+
| FORMAT_MESSAGE_IGNORE_INSERTS
1054+
| FORMAT_MESSAGE_MAX_WIDTH_MASK,
10531055
0, GetLastError(), 0, win_errormsg, 2048, NULL);
10541056
return win_errormsg;
10551057
}

0 commit comments

Comments
 (0)