perform boundary check before searching to prevent security vulnerabilities

This commit is contained in:
albertexye 2024-04-01 14:19:01 -04:00
parent cb15db1f0e
commit 4b10090f70

View File

@ -266,6 +266,7 @@ int utf8len(unsigned char c, bool suppress){
}
int Str::index(const Str& sub, int start) const {
if (start < 0 || start >= this->u8_length()) return -1;
auto p = std::search(data + start, data + size, sub.data, sub.data + sub.size);
if(p == data + size) return -1;
return p - data;