Skip to content

Commit

Permalink
Fix bug found by fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnZhong committed Jan 13, 2023
1 parent 6a0f6ff commit 5dc570c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
}
if (begin != ptr) handler.on_text(begin, ptr);
c = *++ptr; // consume '%'
if (ptr == end) FMT_THROW(format_error("invalid format"));
switch (c) {
case '_':
pad = pad_type::space;
Expand Down
7 changes: 7 additions & 0 deletions test/chrono-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,13 @@ TEST(chrono_test, timestamps_sub_seconds) {
}

TEST(chrono_test, glibc_extensions) {
EXPECT_THROW_MSG((void)fmt::format(runtime("{:%0}"), std::chrono::seconds()),
fmt::format_error, "invalid format");
EXPECT_THROW_MSG((void)fmt::format(runtime("{:%_}"), std::chrono::seconds()),
fmt::format_error, "invalid format");
EXPECT_THROW_MSG((void)fmt::format(runtime("{:%-}"), std::chrono::seconds()),
fmt::format_error, "invalid format");

{
const auto d = std::chrono::hours(1) + std::chrono::minutes(2) +
std::chrono::seconds(3);
Expand Down

0 comments on commit 5dc570c

Please sign in to comment.