diff --git a/src/time_zone_format.cc b/src/time_zone_format.cc index 71e2381..cea6be3 100644 --- a/src/time_zone_format.cc +++ b/src/time_zone_format.cc @@ -974,7 +974,7 @@ bool parse(const std::string& format, const std::string& input, while (std::isspace(*data)) ++data; // parse() must consume the entire input string. - if (*data != '\0') { + if (data != input.data() + input.size()) { if (err != nullptr) *err = "Illegal trailing data in input string"; return false; } diff --git a/src/time_zone_format_test.cc b/src/time_zone_format_test.cc index f2d2b8b..c25b5e3 100644 --- a/src/time_zone_format_test.cc +++ b/src/time_zone_format_test.cc @@ -896,6 +896,9 @@ TEST(Parse, ErrorCases) { EXPECT_FALSE(parse("%Ez", "+-0:00", tz, &tp)); EXPECT_FALSE(parse("%z", "-00-0", tz, &tp)); EXPECT_FALSE(parse("%Ez", "-00:-0", tz, &tp)); + + // Check that we do not accept strings with embedded NULs. + EXPECT_FALSE(parse("%Y", std::string("2026\0payload", 12), tz, &tp)); } TEST(Parse, PosixConversions) {