diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-01-20 13:45:38 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-01-20 17:43:35 +0100 |
commit | 3703e5d019e3d11870f83a129cf6bfea3c682470 (patch) | |
tree | bf1507050000f5408a81099b9b27aac745ca7c9c /src/basic/time-util.c | |
parent | time-util: if a date is unrepresentable, honour style to generate XXX string (diff) | |
download | systemd-3703e5d019e3d11870f83a129cf6bfea3c682470.tar.xz systemd-3703e5d019e3d11870f83a129cf6bfea3c682470.zip |
time-util: move buffer size check after handling of UNIX timestamp style
Diffstat (limited to '')
-rw-r--r-- | src/basic/time-util.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index f427205f0d..081fa01004 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -317,16 +317,6 @@ char *format_timestamp_style( assert(style >= 0); assert(style < _TIMESTAMP_STYLE_MAX); - utc = IN_SET(style, TIMESTAMP_UTC, TIMESTAMP_US_UTC); - us = IN_SET(style, TIMESTAMP_US, TIMESTAMP_US_UTC); - - if (l < (size_t) (3 + /* week day */ - 1 + 10 + /* space and date */ - 1 + 8 + /* space and time */ - (us ? 1 + 6 : 0) + /* "." and microsecond part */ - 1 + 1 + /* space and shortest possible zone */ - 1)) - return NULL; /* Not enough space even for the shortest form. */ if (!timestamp_is_set(t)) return NULL; /* Timestamp is unset */ @@ -338,6 +328,17 @@ char *format_timestamp_style( return buf; } + utc = IN_SET(style, TIMESTAMP_UTC, TIMESTAMP_US_UTC); + us = IN_SET(style, TIMESTAMP_US, TIMESTAMP_US_UTC); + + if (l < (size_t) (3 + /* week day */ + 1 + 10 + /* space and date */ + 1 + 8 + /* space and time */ + (us ? 1 + 6 : 0) + /* "." and microsecond part */ + 1 + 1 + /* space and shortest possible zone */ + 1)) + return NULL; /* Not enough space even for the shortest form. */ + /* Let's not format times with years > 9999 */ if (t > USEC_TIMESTAMP_FORMATTABLE_MAX) { static const char* const xxx[_TIMESTAMP_STYLE_MAX] = { |