Skip to content
Permalink
Browse files Browse the repository at this point in the history
time-util: fix buffer-over-run
Fixes #23928.
  • Loading branch information
yuwata authored and poettering committed Jul 8, 2022
1 parent ef8304d commit 9102c62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/basic/time-util.c
Expand Up @@ -591,7 +591,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
t = b;
}

n = MIN((size_t) k, l);
n = MIN((size_t) k, l-1);

l -= n;
p += n;
Expand Down
5 changes: 5 additions & 0 deletions src/test/test-time-util.c
Expand Up @@ -238,6 +238,11 @@ TEST(format_timespan) {
test_format_timespan_accuracy(1);
test_format_timespan_accuracy(USEC_PER_MSEC);
test_format_timespan_accuracy(USEC_PER_SEC);

/* See issue #23928. */
_cleanup_free_ char *buf;
assert_se(buf = new(char, 5));
assert_se(buf == format_timespan(buf, 5, 100005, 1000));
}

TEST(verify_timezone) {
Expand Down

0 comments on commit 9102c62

Please sign in to comment.