From a6dac311f9b6757caba2415f75f5527283476d5f Mon Sep 17 00:00:00 2001 From: Greg Mann Date: Sat, 10 Oct 2015 18:09:51 -0700 Subject: [PATCH] Check for trailing characters when parsing std::string. --- picojson.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/picojson.h b/picojson.h index 0348790..99df7a7 100644 --- a/picojson.h +++ b/picojson.h @@ -937,7 +937,12 @@ namespace picojson { inline std::string parse(value& out, const std::string& s) { std::string err; - parse(out, s.begin(), s.end(), &err); + std::string::const_iterator begin = s.begin(); + std::string::const_iterator last_char = begin + s.find_last_not_of(" \t\n\r"); + std::string::const_iterator end = parse(out, begin, s.end(), &err); + if (end != last_char + 1 && err.empty()) { + err = "Input string contained non-whitespace trailing characters."; + } return err; }