The same buffer was used for two different IDs, messing up the output. The same idea of using alloca() is applied in a few other places. --- src/journal/journal-file.c | 9 ++++----- src/journal/journald-server.c | 3 +-- src/shared/logs-show.c | 9 ++++----- 3 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 3cb8f79..073e4a4 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -2271,7 +2271,6 @@ fail: } void journal_file_print_header(JournalFile *f) { - char a[33], b[33], c[33]; char x[FORMAT_TIMESTAMP_MAX], y[FORMAT_TIMESTAMP_MAX]; struct stat st; char bytes[FORMAT_BYTES_MAX]; @@ -2298,10 +2297,10 @@ void journal_file_print_header(JournalFile *f) { "Objects: %"PRIu64"\n" "Entry Objects: %"PRIu64"\n", f->path, - sd_id128_to_string(f->header->file_id, a), - sd_id128_to_string(f->header->machine_id, b), - sd_id128_to_string(f->header->boot_id, c), - sd_id128_to_string(f->header->seqnum_id, c), + sd_id128_to_string(f->header->file_id, alloca(33)), + sd_id128_to_string(f->header->machine_id, alloca(33)), + sd_id128_to_string(f->header->boot_id, alloca(33)), + sd_id128_to_string(f->header->seqnum_id, alloca(33)), f->header->state == STATE_OFFLINE ? "OFFLINE" : f->header->state == STATE_ONLINE ? "ONLINE" : f->header->state == STATE_ARCHIVED ? "ARCHIVED" : "UNKNOWN", diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 0bf557c..d46b290 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -90,7 +90,6 @@ DEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode); DEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting"); static uint64_t available_space(Server *s) { - char ids[33]; _cleanup_free_ char *p = NULL; const char *f; sd_id128_t machine; @@ -120,7 +119,7 @@ static uint64_t available_space(Server *s) { assert(m); - p = strappend(f, sd_id128_to_string(machine, ids)); + p = strappend(f, sd_id128_to_string(machine, alloca(33))); if (!p) return 0; diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index a6cd9f6..e58824d 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -363,7 +363,6 @@ static int output_export( OutputFlags flags) { sd_id128_t boot_id; - char sid[33]; int r; usec_t realtime, monotonic; _cleanup_free_ char *cursor = NULL; @@ -400,7 +399,7 @@ static int output_export( cursor, (unsigned long long) realtime, (unsigned long long) monotonic, - sd_id128_to_string(boot_id, sid)); + sd_id128_to_string(boot_id, alloca(33))); SD_JOURNAL_FOREACH_DATA(j, data, length) { @@ -499,7 +498,7 @@ static int output_json( const void *data; size_t length; sd_id128_t boot_id; - char sid[33], *k; + char *k; int r; Hashmap *h = NULL; bool done, separator; @@ -536,7 +535,7 @@ static int output_json( cursor, (unsigned long long) realtime, (unsigned long long) monotonic, - sd_id128_to_string(boot_id, sid)); + sd_id128_to_string(boot_id, alloca(33))); else { if (mode == OUTPUT_JSON_SSE) fputs("data: ", f); @@ -549,7 +548,7 @@ static int output_json( cursor, (unsigned long long) realtime, (unsigned long long) monotonic, - sd_id128_to_string(boot_id, sid)); + sd_id128_to_string(boot_id, alloca(33))); } h = hashmap_new(string_hash_func, string_compare_func); -- 1.8.2.562.g931e949 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel