!4996 Bugfix on BuiltinsRegExp::FlagsBitsToString which flagsStr is OOB

Merge pull request !4996 from chenjingxiang/regexp_flags_br
This commit is contained in:
openharmony_ci 2023-10-18 03:31:08 +00:00 committed by Gitee
commit 00f08f521d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 6 additions and 1 deletions

View File

@ -1949,7 +1949,7 @@ JSTaggedValue BuiltinsRegExp::FlagsBitsToString(JSThread *thread, uint8_t flags)
{
ASSERT((flags & 0x80) == 0); // 0x80: first bit of flags must be 0
BUILTINS_API_TRACE(thread, RegExp, FlagsBitsToString);
uint8_t *flagsStr = new uint8_t[7]; // 7: maximum 6 flags + '\0'
uint8_t *flagsStr = new uint8_t[RegExpParser::FLAG_NUM + 1]; // FLAG_NUM flags + '\0'
size_t flagsLen = 0;
if (flags & RegExpParser::FLAG_HASINDICES) {
flagsStr[flagsLen] = 'd';

View File

@ -41,6 +41,7 @@ public:
static constexpr auto FLAG_UTF16 = (1U << 4U);
static constexpr auto FLAG_STICKY = (1U << 5U);
static constexpr auto FLAG_HASINDICES = (1U << 6U);
static constexpr uint32_t FLAG_NUM = 7;
static const uint32_t KEY_EOF = UINT32_MAX;
static constexpr int CLASS_RANGE_BASE = 0x40000000;
static constexpr uint32_t NUM_CAPTURE__OFFSET = 4;

View File

@ -30,3 +30,4 @@ dgm
1,2
1,2
undefined
dgimsuy

View File

@ -45,3 +45,6 @@ var result2 = "bπb".match(/(π)/du).indices;
print(result2[0]);
print(result2[1]);
print(result2.groups);
var regexpFlags = new RegExp("", "dgimsuy").flags;
print(regexpFlags);