mirror of
https://github.com/fmtlib/fmt.git
synced 2026-09-13 14:22:26 +08:00
Fix out-of-bounds read in error code format parsing (#4934)
This commit is contained in:
parent
7071103cea
commit
8a7aea0422
@ -549,9 +549,10 @@ template <> struct formatter<std::error_code> {
|
||||
if (it == end) return it;
|
||||
|
||||
it = detail::parse_align(it, end, specs_);
|
||||
if (it == end) return it;
|
||||
|
||||
char c = *it;
|
||||
if (it != end && ((c >= '1' && c <= '9') || c == '{'))
|
||||
if ((c >= '1' && c <= '9') || c == '{')
|
||||
it = detail::parse_width(it, end, specs_, width_ref_, ctx);
|
||||
|
||||
if (it != end && *it == '?') {
|
||||
|
||||
@ -349,6 +349,16 @@ TEST(std_test, error_code) {
|
||||
"{\"generic:42\": 0}");
|
||||
}
|
||||
|
||||
TEST(std_test, error_code_truncated_alignment) {
|
||||
// No null terminator: reading past the format string must be detectable.
|
||||
const char format[] = {'{', ':', '>'};
|
||||
auto ec = std::error_code(42, std::generic_category());
|
||||
EXPECT_THROW(
|
||||
(void)fmt::vformat(fmt::string_view(format, sizeof(format)),
|
||||
fmt::make_format_args(ec)),
|
||||
fmt::format_error);
|
||||
}
|
||||
|
||||
template <typename Catch> void exception_test() {
|
||||
try {
|
||||
throw std::runtime_error("Test Exception");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user