diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2016-03-29 11:54:57 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2016-03-29 11:55:19 -0400 |
commit | 7abc1571652a924ba4258bda0a26df2de03b790e (patch) | |
tree | d606955e4a266c6ebf185c2ce87bf0f8f391ffdb /src/backend/port/win32 | |
parent | 61d66c44f18c73094a50a2ef97d26cc03e171dc0 (diff) | |
download | postgresql-7abc1571652a924ba4258bda0a26df2de03b790e.tar.gz |
Avoid possibly-unsafe use of Windows' FormatMessage() function.
Whenever this function is used with the FORMAT_MESSAGE_FROM_SYSTEM flag,
it's good practice to include FORMAT_MESSAGE_IGNORE_INSERTS as well.
Otherwise, if the message contains any %n insertion markers, the function
will try to fetch argument strings to substitute --- which we are not
passing, possibly leading to a crash. This is exactly analogous to the
rule about not giving printf() a format string you're not in control of.
Noted and patched by Christian Ullrich.
Back-patch to all supported branches.
Diffstat (limited to 'src/backend/port/win32')
-rw-r--r-- | src/backend/port/win32/socket.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/backend/port/win32/socket.c b/src/backend/port/win32/socket.c index d1ea578b1f..747304cee4 100644 --- a/src/backend/port/win32/socket.c +++ b/src/backend/port/win32/socket.c @@ -658,7 +658,9 @@ pgwin32_socket_strerror(int err) } ZeroMemory(&wserrbuf, sizeof(wserrbuf)); - if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, + if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_FROM_HMODULE, handleDLL, err, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), |