Fix incorrect message-printing in win32security.c.

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
REL_14_STABLE
Tom Lane 2 months ago
parent 715eb62e30
commit e91eb4ad66
  1. 16
      src/backend/utils/error/elog.c
  2. 1
      src/include/utils/elog.h
  3. 4
      src/port/win32security.c

@ -3577,13 +3577,24 @@ write_stderr(const char *fmt,...)
{ {
va_list ap; 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 #ifdef WIN32
char errbuf[2048]; /* Arbitrary size? */ char errbuf[2048]; /* Arbitrary size? */
#endif #endif
fmt = _(fmt); fmt = _(fmt);
va_start(ap, fmt);
#ifndef WIN32 #ifndef WIN32
/* On Unix, we just fprintf to stderr */ /* On Unix, we just fprintf to stderr */
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
@ -3606,7 +3617,6 @@ write_stderr(const char *fmt,...)
fflush(stderr); fflush(stderr);
} }
#endif #endif
va_end(ap);
} }

@ -452,6 +452,7 @@ extern void set_syslog_parameters(const char *ident, int facility);
* safely (memory context, GUC load etc) * safely (memory context, GUC load etc)
*/ */
extern void write_stderr(const char *fmt,...) pg_attribute_printf(1, 2); 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 * Write a message to STDERR using only async-signal-safe functions. This can

@ -31,9 +31,9 @@ log_error(const char *fmt,...)
va_start(ap, fmt); va_start(ap, fmt);
#ifndef FRONTEND #ifndef FRONTEND
write_stderr(fmt, ap); vwrite_stderr(fmt, ap);
#else #else
fprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
#endif #endif
va_end(ap); va_end(ap);
} }

Loading…
Cancel
Save