]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix incorrect message-printing in win32security.c.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 13 Oct 2025 21:56:45 +0000 (17:56 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 13 Oct 2025 21:56:45 +0000 (17:56 -0400)
log_error() would probably fail completely if used, and would
certainly print garbage for anything that needed to be interpolated
into the message, because it was failing to use the correct printing
subroutine for a va_list argument.

This bug likely went undetected because the error cases this code
is used for are rarely exercised - they only occur when Windows
security API calls fail catastrophically (out of memory, security
subsystem corruption, etc).

The FRONTEND variant can be fixed just by calling vfprintf()
instead of fprintf().  However, there was no va_list variant
of write_stderr(), so create one by refactoring that function.
Following the usual naming convention for such things, call
it vwrite_stderr().

Author: Bryan Green <dbryan.green@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAF+pBj8goe4fRmZ0V3Cs6eyWzYLvK+HvFLYEYWG=TzaM+tWPnw@mail.gmail.com
Backpatch-through: 13

src/backend/utils/error/elog.c
src/include/utils/elog.h
src/port/win32security.c

index 6198fd87120e31d3de686bc52a0b487f98ddd294..079a389ce48356f1fa6c8b4223ecbd1b389d8957 100644 (file)
@@ -3391,13 +3391,24 @@ write_stderr(const char *fmt,...)
 {
        va_list         ap;
 
+       va_start(ap, fmt);
+       vwrite_stderr(fmt, ap);
+       va_end(ap);
+}
+
+
+/*
+ * Write errors to stderr (or by equal means when stderr is
+ * not available) - va_list version
+ */
+void
+vwrite_stderr(const char *fmt, va_list ap)
+{
 #ifdef WIN32
        char            errbuf[2048];   /* Arbitrary size? */
 #endif
 
        fmt = _(fmt);
-
-       va_start(ap, fmt);
 #ifndef WIN32
        /* On Unix, we just fprintf to stderr */
        vfprintf(stderr, fmt, ap);
@@ -3420,7 +3431,6 @@ write_stderr(const char *fmt,...)
                fflush(stderr);
        }
 #endif
-       va_end(ap);
 }
 
 
index 561c15e7d11822eeb2cc8b2c453d7db3fbea1d6f..edf1a4926a1b90fd052711871c92f3b160297ae1 100644 (file)
@@ -466,6 +466,7 @@ extern void set_syslog_parameters(const char *ident, int facility);
  * safely (memory context, GUC load etc)
  */
 extern void write_stderr(const char *fmt,...) pg_attribute_printf(1, 2);
+extern void vwrite_stderr(const char *fmt, va_list ap) pg_attribute_printf(1, 0);
 
 /*
  * Write a message to STDERR using only async-signal-safe functions.  This can
index 1235199f2fbc938cfc066259f0d9199f16a13978..5632386a0b144ed672868c24e8eaa844ab9f214e 100644 (file)
@@ -31,9 +31,9 @@ log_error(const char *fmt,...)
 
        va_start(ap, fmt);
 #ifndef FRONTEND
-       write_stderr(fmt, ap);
+       vwrite_stderr(fmt, ap);
 #else
-       fprintf(stderr, fmt, ap);
+       vfprintf(stderr, fmt, ap);
 #endif
        va_end(ap);
 }