Make a copy of ap in sudo_debug_vprintf2() in case the static buffer
is not big enough and we need to call vasprintf().
This commit is contained in:
@@ -370,8 +370,7 @@ void
|
|||||||
sudo_debug_vprintf2(const char *func, const char *file, int lineno, int level,
|
sudo_debug_vprintf2(const char *func, const char *file, int lineno, int level,
|
||||||
const char *fmt, va_list ap)
|
const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
int buflen, pri, subsys, saved_errno = errno;
|
int pri, subsys;
|
||||||
char static_buf[1024], *buf = static_buf;
|
|
||||||
|
|
||||||
if (!sudo_debug_initialized)
|
if (!sudo_debug_initialized)
|
||||||
return;
|
return;
|
||||||
@@ -382,10 +381,15 @@ sudo_debug_vprintf2(const char *func, const char *file, int lineno, int level,
|
|||||||
|
|
||||||
/* Make sure we want debug info at this level. */
|
/* Make sure we want debug info at this level. */
|
||||||
if (subsys < num_subsystems && sudo_debug_settings[subsys] >= pri) {
|
if (subsys < num_subsystems && sudo_debug_settings[subsys] >= pri) {
|
||||||
|
char static_buf[1024], *buf = static_buf;
|
||||||
|
int buflen, saved_errno = errno;
|
||||||
|
va_list ap2;
|
||||||
|
|
||||||
|
va_copy(ap2, ap);
|
||||||
buflen = fmt ? vsnprintf(static_buf, sizeof(static_buf), fmt, ap) : 0;
|
buflen = fmt ? vsnprintf(static_buf, sizeof(static_buf), fmt, ap) : 0;
|
||||||
if (buflen >= (int)sizeof(static_buf)) {
|
if (buflen >= (int)sizeof(static_buf)) {
|
||||||
/* Not enough room in static buf, allocate dynamically. */
|
/* Not enough room in static buf, allocate dynamically. */
|
||||||
buflen = vasprintf(&buf, fmt, ap);
|
buflen = vasprintf(&buf, fmt, ap2);
|
||||||
}
|
}
|
||||||
if (buflen != -1) {
|
if (buflen != -1) {
|
||||||
int errcode = ISSET(level, SUDO_DEBUG_ERRNO) ? saved_errno : 0;
|
int errcode = ISSET(level, SUDO_DEBUG_ERRNO) ? saved_errno : 0;
|
||||||
@@ -396,9 +400,9 @@ sudo_debug_vprintf2(const char *func, const char *file, int lineno, int level,
|
|||||||
if (buf != static_buf)
|
if (buf != static_buf)
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
}
|
va_end(ap2);
|
||||||
|
|
||||||
errno = saved_errno;
|
errno = saved_errno;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NO_VARIADIC_MACROS
|
#ifdef NO_VARIADIC_MACROS
|
||||||
|
Reference in New Issue
Block a user