Skip to content

Commit 99e7941

Browse files
committed
Fixes cctz::parse() to reject input with embedded NULs
Original report: abseil/abseil-cpp#2014
1 parent 5a446d2 commit 99e7941

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/time_zone_format.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ bool parse(const std::string& format, const std::string& input,
974974
while (std::isspace(*data)) ++data;
975975

976976
// parse() must consume the entire input string.
977-
if (*data != '\0') {
977+
if (data != input.data() + input.size()) {
978978
if (err != nullptr) *err = "Illegal trailing data in input string";
979979
return false;
980980
}

src/time_zone_format_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,9 @@ TEST(Parse, ErrorCases) {
896896
EXPECT_FALSE(parse("%Ez", "+-0:00", tz, &tp));
897897
EXPECT_FALSE(parse("%z", "-00-0", tz, &tp));
898898
EXPECT_FALSE(parse("%Ez", "-00:-0", tz, &tp));
899+
900+
// Check that we do not accept strings with embedded NULs.
901+
EXPECT_FALSE(parse("%Y", std::string("2026\0payload", 12), tz, &tp));
899902
}
900903

901904
TEST(Parse, PosixConversions) {

0 commit comments

Comments
 (0)