There are some instances of calls to FormatMessage() with the FORMAT_MESSAGE_FROM_SYSTEM flag that omit the FORMAT_MESSAGE_IGNORE_INSERTS flag. The effect of that is that if the requested message string contains any insertion markers, the call to FormatMessage() will fail because none of these calls pass an argument list.

This patch adds the ...IGNORE_INSERTS flag to these calls.

The documentation for FormatMessage() does not clearly say that a NULL argument list is not an implicit IGNORE_INSERTS flag, but Chen does at <https://blogs.msdn.microsoft.com/oldnewthing/20071128-00/?p=24353>.

--
Christian
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
new file mode 100644
index 7f1ae8c..dfbf278
*** a/src/backend/libpq/auth.c
--- b/src/backend/libpq/auth.c
*************** pg_SSPI_error(int severity, const char *
*** 1011,1017 ****
  {
        char            sysmsg[256];
  
!       if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, r, 0,
                                          sysmsg, sizeof(sysmsg), NULL) == 0)
                ereport(severity,
                                (errmsg_internal("%s", errmsg),
--- 1011,1018 ----
  {
        char            sysmsg[256];
  
!       if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | 
FORMAT_MESSAGE_FROM_SYSTEM,
!                                         NULL, r, 0,
                                          sysmsg, sizeof(sysmsg), NULL) == 0)
                ereport(severity,
                                (errmsg_internal("%s", errmsg),
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
new file mode 100644
index cd863a5..8fd90fb
*** a/src/interfaces/libpq/fe-auth.c
--- b/src/interfaces/libpq/fe-auth.c
*************** pg_SSPI_error(PGconn *conn, const char *
*** 234,240 ****
  {
        char            sysmsg[256];
  
!       if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, r, 0,
                                          sysmsg, sizeof(sysmsg), NULL) == 0)
                printfPQExpBuffer(&conn->errorMessage, "%s: SSPI error %x\n",
                                                  mprefix, (unsigned int) r);
--- 234,241 ----
  {
        char            sysmsg[256];
  
!       if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | 
FORMAT_MESSAGE_FROM_SYSTEM,
!                                         NULL, r, 0,
                                          sysmsg, sizeof(sysmsg), NULL) == 0)
                printfPQExpBuffer(&conn->errorMessage, "%s: SSPI error %x\n",
                                                  mprefix, (unsigned int) r);
diff --git a/src/port/dirmod.c b/src/port/dirmod.c
new file mode 100644
index 8053d16..5ee5e4e
*** a/src/port/dirmod.c
--- b/src/port/dirmod.c
*************** pgsymlink(const char *oldpath, const cha
*** 206,212 ****
                LPSTR           msg;
  
                errno = 0;
!               FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_FROM_SYSTEM,
                                          NULL, GetLastError(),
                                          MAKELANGID(LANG_ENGLISH, 
SUBLANG_DEFAULT),
                                          (LPSTR) &msg, 0, NULL);
--- 206,212 ----
                LPSTR           msg;
  
                errno = 0;
!               FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
                                          NULL, GetLastError(),
                                          MAKELANGID(LANG_ENGLISH, 
SUBLANG_DEFAULT),
                                          (LPSTR) &msg, 0, NULL);
*************** pgreadlink(const char *path, char *buf,
*** 281,287 ****
                LPSTR           msg;
  
                errno = 0;
!               FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_FROM_SYSTEM,
                                          NULL, GetLastError(),
                                          MAKELANGID(LANG_ENGLISH, 
SUBLANG_DEFAULT),
                                          (LPSTR) &msg, 0, NULL);
--- 281,287 ----
                LPSTR           msg;
  
                errno = 0;
!               FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
                                          NULL, GetLastError(),
                                          MAKELANGID(LANG_ENGLISH, 
SUBLANG_DEFAULT),
                                          (LPSTR) &msg, 0, NULL);
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to