summaryrefslogtreecommitdiff
path: root/src/shared/log.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-09-24 23:22:19 +0200
committerLennart Poettering <lennart@poettering.net>2012-09-24 23:26:46 +0200
commit963ddb917de3140308ee62fb642b2307a577a39e (patch)
treeedfad917a0360b81c69a5030fe13b5716a687e46 /src/shared/log.c
parent1920e37ef9fec04a1fd882f66bfa7a9a5b91c536 (diff)
log: fix repeated invocation of vsnprintf()/vaprintf() in log_struct()
https://bugs.freedesktop.org/show_bug.cgi?id=55213
Diffstat (limited to 'src/shared/log.c')
-rw-r--r--src/shared/log.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/shared/log.c b/src/shared/log.c
index b61845859f..63578683ab 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -27,6 +27,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <stddef.h>
+#include <printf.h>
#include "log.h"
#include "util.h"
@@ -705,11 +706,23 @@ int log_struct_internal(
va_start(ap, format);
while (format && n + 1 < ELEMENTSOF(iovec)) {
char *buf;
+ va_list aq;
- if (vasprintf(&buf, format, ap) < 0) {
+ /* We need to copy the va_list structure,
+ * since vasprintf() leaves it afterwards at
+ * an undefined location */
+
+ va_copy(aq, ap);
+ if (vasprintf(&buf, format, aq) < 0) {
+ va_end(aq);
r = -ENOMEM;
goto finish;
}
+ va_end(aq);
+
+ /* Now, jump enough ahead, so that we point to
+ * the next format string */
+ VA_FORMAT_ADVANCE(format, ap);
IOVEC_SET_STRING(iovec[n++], buf);
@@ -742,8 +755,11 @@ int log_struct_internal(
va_start(ap, format);
while (format) {
+ va_list aq;
- vsnprintf(buf, sizeof(buf), format, ap);
+ va_copy(aq, ap);
+ vsnprintf(buf, sizeof(buf), format, aq);
+ va_end(aq);
char_array_0(buf);
if (startswith(buf, "MESSAGE=")) {
@@ -751,6 +767,8 @@ int log_struct_internal(
break;
}
+ VA_FORMAT_ADVANCE(format, ap);
+
format = va_arg(ap, char *);
}
va_end(ap);