string/constVarList: fix UAF

This commit is contained in:
Vaxry 2025-11-05 15:03:55 +00:00
parent 164a30b3d8
commit 9637961a55
Signed by: vaxry
GPG key ID: 665806380871D640
2 changed files with 5 additions and 1 deletions

View file

@ -33,7 +33,7 @@ CConstVarList::CConstVarList(const std::string& in, const size_t lastArgNo, cons
if (removeEmpty && s.empty())
continue;
if (++idx == lastArgNo) {
m_args.emplace_back(trim(in.substr(pos)));
m_args.emplace_back(trim(std::string_view{m_str}.substr(pos)));
break;
}
pos += s.size() + 1;

View file

@ -43,6 +43,10 @@ int main(int argc, char** argv, char** envp) {
EXPECT(listConst[0], "hello");
EXPECT(listConst[1], "world!");
CConstVarList listConst2("0 set", 2, ' ');
EXPECT(listConst2[0], "0");
EXPECT(listConst2[1], "set");
std::string hello = "hello world!";
replaceInString(hello, "hello", "hi");
EXPECT(hello, "hi world!");