Help markup parser: Avoid UB and unused param when checking closing tag

This commit is contained in:
Celtic Minstrel 2024-08-06 09:21:05 -04:00 committed by Celtic Minstrel
parent 2e3c401f45
commit 62c03ad779

View file

@ -1582,11 +1582,20 @@ static std::pair<std::string, std::string> parse_attribute(std::string::const_it
static void check_closing_tag(std::string::const_iterator& beg, std::string::const_iterator end, std::string_view match)
{
size_t remaining = end - beg;
assert(remaining >= 2 && *beg == '<' && *(beg + 1) == '/');
if(remaining < match.size() + 3) {
throw parse_error("Unexpected eos in closing tag");
}
beg += 2;
if(!std::equal(match.begin(), match.end(), beg)) {
throw parse_error("Mismatched closing tag");
}
beg += match.size() + 1;
beg += match.size();
if(*beg != '>') {
throw parse_error("Unterminated closing tag");
}
++beg;
}
static std::pair<std::string, config> parse_tag(std::string::const_iterator& beg, std::string::const_iterator end);