summaryrefslogtreecommitdiff
path: root/src/port
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-03-29 11:54:57 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-03-29 11:55:19 -0400
commit7abc1571652a924ba4258bda0a26df2de03b790e (patch)
treed606955e4a266c6ebf185c2ce87bf0f8f391ffdb /src/port
parent61d66c44f18c73094a50a2ef97d26cc03e171dc0 (diff)
downloadpostgresql-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/port')
-rw-r--r--src/port/dirmod.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/port/dirmod.c b/src/port/dirmod.c
index 8053d16ebf..fe2b815ff6 100644
--- a/src/port/dirmod.c
+++ b/src/port/dirmod.c
@@ -206,7 +206,9 @@ pgsymlink(const char *oldpath, const char *newpath)
LPSTR msg;
errno = 0;
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_IGNORE_INSERTS |
+ FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
(LPSTR) &msg, 0, NULL);
@@ -281,7 +283,9 @@ pgreadlink(const char *path, char *buf, size_t size)
LPSTR msg;
errno = 0;
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_IGNORE_INSERTS |
+ FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
(LPSTR) &msg, 0, NULL);