mirror of
https://github.com/fmtlib/fmt.git
synced 2026-06-15 00:16:15 +08:00
fix out-of-bounds read in basic_format_args::get (#4800)
This commit is contained in:
parent
e60274b29c
commit
128ba144ab
@ -2593,7 +2593,7 @@ template <typename Context> class basic_format_args {
|
||||
FMT_CONSTEXPR auto get(int id) const -> format_arg {
|
||||
auto arg = format_arg();
|
||||
if (!is_packed()) {
|
||||
if (id < max_size()) arg = args_[id];
|
||||
if (unsigned(id) < unsigned(max_size())) arg = args_[id];
|
||||
return arg;
|
||||
}
|
||||
if (unsigned(id) >= detail::max_packed_args) return arg;
|
||||
|
||||
@ -116,6 +116,17 @@ TEST(printf_test, invalid_arg_index) {
|
||||
"argument not found");
|
||||
}
|
||||
|
||||
TEST(printf_test, zero_positional_width_precision) {
|
||||
// A '0' positional index for a '*' width or precision must be rejected. Use
|
||||
// enough arguments to exercise the unpacked argument storage path.
|
||||
EXPECT_THROW_MSG(test_sprintf("%*0$d", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
|
||||
13, 14, 15, 16),
|
||||
format_error, "argument not found");
|
||||
EXPECT_THROW_MSG(test_sprintf("%.*0$d", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
|
||||
13, 14, 15, 16),
|
||||
format_error, "argument not found");
|
||||
}
|
||||
|
||||
TEST(printf_test, default_align_right) {
|
||||
EXPECT_PRINTF(" 42", "%5d", 42);
|
||||
EXPECT_PRINTF(" abc", "%5s", "abc");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user