]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/format-table: allocate buffer of sufficient size
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 5 Jul 2021 19:29:11 +0000 (21:29 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Jul 2021 16:01:47 +0000 (18:01 +0200)
(cherry picked from commit 6dc57047ff0f1f9e98938ffb172dae06e6868b94)
(cherry picked from commit e6407ca25852dadec355df2e6fdc92d1f189bceb)
(cherry picked from commit d442b879abac5bcaf7756e53e304fd0ade36d49d)

src/shared/format-table.c

index 31c976d1e359c98e3cfd6e5ebdf42ec40a02538e..702edc7ece7a865d391e22b4071d888e0aee1d0d 100644 (file)
@@ -1370,7 +1370,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
                 _cleanup_free_ char *p;
                 char *ret;
 
-                p = new(char, FORMAT_TIMESTAMP_MAX);
+                p = new(char, d->type == TABLE_TIMESTAMP_RELATIVE ? FORMAT_TIMESTAMP_RELATIVE_MAX : FORMAT_TIMESTAMP_MAX);
                 if (!p)
                         return NULL;
 
@@ -1379,7 +1379,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
                 else if (d->type == TABLE_TIMESTAMP_UTC)
                         ret = format_timestamp_style(p, FORMAT_TIMESTAMP_MAX, d->timestamp, TIMESTAMP_UTC);
                 else
-                        ret = format_timestamp_relative(p, FORMAT_TIMESTAMP_MAX, d->timestamp);
+                        ret = format_timestamp_relative(p, FORMAT_TIMESTAMP_RELATIVE_MAX, d->timestamp);
                 if (!ret)
                         return "n/a";