Commit 9ce1ba6f8b2d1ce8cc6d09ec5d9aaac38e767d9c

Pali Rohár 2019-05-21T00:35:11

Call FormatMessage() with FORMAT_MESSAGE_IGNORE_INSERTS Documentation says: 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
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/dlfcn.c b/dlfcn.c
index 69670d1..993808d 100644
--- a/dlfcn.c
+++ b/dlfcn.c
@@ -157,7 +157,7 @@ static void save_err_str( const char *str )
     error_buffer[pos++] = ':';
     error_buffer[pos++] = ' ';
 
-    ret = FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwMessageId,
+    ret = FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwMessageId,
         MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
         error_buffer+pos, (DWORD) (sizeof(error_buffer)-pos), NULL );
     pos += ret;