X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournal-send.c;h=8589d94479456d055a293f8ba2f40aec041ba625;hb=0ce8860a15fb08ac358fb9c5347bd20c0bcdebcd;hp=b192f1fb888738cfaa25a80ac7ee6e14594d1324;hpb=a6e87e90ede66815989ba2db92a07102a69906fe;p=elogind.git diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c index b192f1fb8..8589d9447 100644 --- a/src/journal/journal-send.c +++ b/src/journal/journal-send.c @@ -25,6 +25,7 @@ #include #include #include +#include #define SD_JOURNAL_SUPPRESS_LOCATION @@ -121,6 +122,7 @@ static int fill_iovec_sprintf(const char *format, va_list ap, int extra, struct while (format) { struct iovec *c; char *buffer; + va_list aq; if (i >= n) { n = MAX(i*2, 4); @@ -133,10 +135,15 @@ static int fill_iovec_sprintf(const char *format, va_list ap, int extra, struct iov = c; } - if (vasprintf(&buffer, format, ap) < 0) { + va_copy(aq, ap); + if (vasprintf(&buffer, format, aq) < 0) { + va_end(aq); r = -ENOMEM; goto fail; } + va_end(aq); + + VA_FORMAT_ADVANCE(format, ap); IOVEC_SET_STRING(iov[i++], buffer); @@ -498,10 +505,10 @@ _public_ int sd_journal_printv_with_location(int priority, const char *file, con /* func is initialized from __func__ which is not a macro, but * a static const char[], hence cannot easily be prefixed with * CODE_FUNC=, hence let's do it manually here. */ - fl = strlen(func); + fl = strlen(func) + 1; f = alloca(fl + 10); memcpy(f, "CODE_FUNC=", 10); - memcpy(f + 10, func, fl + 1); + memcpy(f + 10, func, fl); zero(iov); IOVEC_SET_STRING(iov[0], buffer); @@ -529,10 +536,10 @@ _public_ int sd_journal_send_with_location(const char *file, const char *line, c goto finish; } - fl = strlen(func); + fl = strlen(func) + 1; f = alloca(fl + 10); memcpy(f, "CODE_FUNC=", 10); - memcpy(f + 10, func, fl + 1); + memcpy(f + 10, func, fl); IOVEC_SET_STRING(iov[0], file); IOVEC_SET_STRING(iov[1], line); @@ -567,10 +574,10 @@ _public_ int sd_journal_sendv_with_location( niov = alloca(sizeof(struct iovec) * (n + 3)); memcpy(niov, iov, sizeof(struct iovec) * n); - fl = strlen(func); + fl = strlen(func) + 1; f = alloca(fl + 10); memcpy(f, "CODE_FUNC=", 10); - memcpy(f + 10, func, fl + 1); + memcpy(f + 10, func, fl); IOVEC_SET_STRING(niov[n++], file); IOVEC_SET_STRING(niov[n++], line); @@ -588,10 +595,10 @@ _public_ int sd_journal_perror_with_location( size_t fl; char *f; - fl = strlen(func); + fl = strlen(func) + 1; f = alloca(fl + 10); memcpy(f, "CODE_FUNC=", 10); - memcpy(f + 10, func, fl + 1); + memcpy(f + 10, func, fl); IOVEC_SET_STRING(iov[0], file); IOVEC_SET_STRING(iov[1], line);