diff options
author | Andy Soffer <asoffer@google.com> | 2022-10-10 14:53:27 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-10-10 14:54:32 -0700 |
commit | 845610e80b66aa3d834f4d1b401133919bf7fadb (patch) | |
tree | b785139b62abd6770a80d253c2ed9640d9c0a60b /absl/strings/internal/str_format/parser.cc | |
parent | a0b5e3273bf6780b83c6e7fab23a5a92d6a005b7 (diff) |
Fix a bug in StrFormat. This issue would have been caught by any compile-time
checking but can happen for incorrect formats parsed via ParsedFormat::New.
Specifically, if a user were to add length modifiers with 'v', for example the
incorrect format string "%hv", the ParsedFormat would incorrectly be allowed.
PiperOrigin-RevId: 480183817
Change-Id: I8510c13189fdf807cdaa7f2e1b7ed9fba2aaefb9
Diffstat (limited to 'absl/strings/internal/str_format/parser.cc')
-rw-r--r-- | absl/strings/internal/str_format/parser.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/absl/strings/internal/str_format/parser.cc b/absl/strings/internal/str_format/parser.cc index f9bb6615..13731ee2 100644 --- a/absl/strings/internal/str_format/parser.cc +++ b/absl/strings/internal/str_format/parser.cc @@ -202,9 +202,7 @@ const char *ConsumeConversion(const char *pos, const char *const end, auto tag = GetTagForChar(c); - if (*(pos - 1) == 'v' && *(pos - 2) != '%') { - return nullptr; - } + if (ABSL_PREDICT_FALSE(c == 'v' && (pos - original_pos) != 1)) return nullptr; if (ABSL_PREDICT_FALSE(!tag.is_conv())) { if (ABSL_PREDICT_FALSE(!tag.is_length())) return nullptr; @@ -223,6 +221,8 @@ const char *ConsumeConversion(const char *pos, const char *const end, conv->length_mod = length_mod; } tag = GetTagForChar(c); + + if (ABSL_PREDICT_FALSE(c == 'v')) return nullptr; if (ABSL_PREDICT_FALSE(!tag.is_conv())) return nullptr; } |