Merge pull request #10696

d42de75 tests: cover truncated \u escape at end of buffer in match_string2 (alhudz)
524b0d0 fix off-by-one over-read in match_string2 unicode escape parsing (alhudz)
This commit is contained in:
tobtoht
2026-06-07 18:35:16 +00:00
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -129,7 +129,7 @@ namespace misc_utils
case '/': //Slash character
val.push_back('/');break;
case 'u': //Unicode code point
if (buf_end - it < 4)
if (buf_end - it < 5)
{
ASSERT_MES_AND_THROW("Invalid Unicode escape sequence");
}
+10
View File
@@ -1856,6 +1856,16 @@ TEST(parsing, unicode)
si = s.begin();
EXPECT_THROW(epee::misc_utils::parse::match_string2(si, s.end(), bs), std::runtime_error);
// truncated \u escape with buf_end right after the hex digits must throw,
// not read past buf_end (the closing quote is absent here on purpose)
s = "\"\\u123";
si = s.begin();
EXPECT_THROW(epee::misc_utils::parse::match_string2(si, s.end(), bs), std::runtime_error);
s = "\"\\u";
si = s.begin();
EXPECT_THROW(epee::misc_utils::parse::match_string2(si, s.end(), bs), std::runtime_error);
s = "\"\\u1234\"";
si = s.begin();
epee::misc_utils::parse::match_string2(si, s.end(), bs);