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:54:57 -0400 |
commit | 11cc7bb8825efc74c9418f6e88d448cc253c47b0 (patch) | |
tree | 8046e4ed03a6b3bf5ca63952dc776231b17c225a /src/port/dirmod.c | |
parent | a3c643938166abed9a390cdbd8a5df09bfe39523 (diff) |
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/dirmod.c')
-rw-r--r-- | src/port/dirmod.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/port/dirmod.c b/src/port/dirmod.c index fde9736f4a0..d544555be5b 100644 --- a/src/port/dirmod.c +++ b/src/port/dirmod.c @@ -207,7 +207,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); @@ -282,7 +284,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); |