Skip to content

Commit

Permalink
time-util: fix buffer-over-run
Browse files Browse the repository at this point in the history
Fixes #23928.

(cherry picked from commit 9102c625a673a3246d7e73d8737f3494446bad4e)

Resolves: RHEL-18768
  • Loading branch information
yuwata authored and brozs committed Jan 15, 2024
1 parent 90f673b commit b2c54cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/basic/time-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,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
6 changes: 6 additions & 0 deletions src/test/test-time-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ int main(int argc, char *argv[]) {
test_format_timespan(1);
test_format_timespan(USEC_PER_MSEC);
test_format_timespan(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_timezone_is_valid();
test_get_timezones();
test_usec_add();
Expand Down

0 comments on commit b2c54cc

Please sign in to comment.