Modify code security specification alarm

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IADY90?from=project-issue

Signed-off-by: chenjx-huawei <chenjingxiang1@huawei.com>
Change-Id: I35809ac0934443449799097b29a3d20cb1666b80
This commit is contained in:
chenjx-huawei 2024-07-21 15:28:08 +08:00
parent 783cc8b666
commit 9cd3ce839c
6 changed files with 60 additions and 54 deletions

View File

@ -25,8 +25,9 @@ class AtomicHelper final {
public:
struct SubFun {
template<typename T>
T operator()(T *ptr, const T *arg) const
T operator()(T *ptr, const T *arg, [[maybe_unused]] uint32_t length) const
{
ASSERT(length >= 1); // 1: max argnum
std::atomic<T> *atomicValue = reinterpret_cast<std::atomic<T> *>(ptr);
return atomicValue->fetch_sub(arg[0], std::memory_order_seq_cst);
}
@ -34,8 +35,9 @@ public:
struct AddFun {
template<typename T>
T operator()(T *ptr, const T *arg) const
T operator()(T *ptr, const T *arg, [[maybe_unused]] uint32_t length) const
{
ASSERT(length >= 1); // 1: max argnum
std::atomic<T> *atomicValue = reinterpret_cast<std::atomic<T> *>(ptr);
return atomicValue->fetch_add(arg[0], std::memory_order_seq_cst);
}
@ -43,8 +45,9 @@ public:
struct AndFun {
template<typename T>
T operator()(T *ptr, const T *arg) const
T operator()(T *ptr, const T *arg, [[maybe_unused]] uint32_t length) const
{
ASSERT(length >= 1); // 1: max argnum
std::atomic<T> *atomicValue = reinterpret_cast<std::atomic<T> *>(ptr);
return atomicValue->fetch_and(arg[0], std::memory_order_seq_cst);
}
@ -52,8 +55,9 @@ public:
struct OrFun {
template<typename T>
T operator()(T *ptr, const T *arg) const
T operator()(T *ptr, const T *arg, [[maybe_unused]] uint32_t length) const
{
ASSERT(length >= 1); // 1: max argnum
std::atomic<T> *atomicValue = reinterpret_cast<std::atomic<T> *>(ptr);
return atomicValue->fetch_or(arg[0], std::memory_order_seq_cst);
}
@ -61,8 +65,9 @@ public:
struct XorFun {
template<typename T>
T operator()(T *ptr, const T *arg) const
T operator()(T *ptr, const T *arg, [[maybe_unused]] uint32_t length) const
{
ASSERT(length >= 1); // 1: max argnum
std::atomic<T> *atomicValue = reinterpret_cast<std::atomic<T> *>(ptr);
return atomicValue->fetch_xor(arg[0], std::memory_order_seq_cst);
}
@ -70,8 +75,9 @@ public:
struct CompareExchangeFun {
template<typename T>
T operator()(T *ptr, const T *arg) const
T operator()(T *ptr, const T *arg, [[maybe_unused]] uint32_t length) const
{
ASSERT(length >= 2); // 2: max argnum
T a = arg[0];
std::atomic<T> *atomicValue = reinterpret_cast<std::atomic<T> *>(ptr);
atomicValue->compare_exchange_strong(a, arg[1], std::memory_order_seq_cst);
@ -81,8 +87,9 @@ public:
struct ExchangeFun {
template<typename T>
T operator()(T *ptr, const T *arg) const
T operator()(T *ptr, const T *arg, [[maybe_unused]] uint32_t length) const
{
ASSERT(length >= 1); // 1: max argnum
std::atomic<T> *atomicValue = reinterpret_cast<std::atomic<T> *>(ptr);
return atomicValue->exchange(arg[0], std::memory_order_seq_cst);
}

View File

@ -380,18 +380,18 @@ JSTaggedValue BuiltinsAtomics::HandleWithUint8(JSThread *thread, uint32_t size,
BUILTINS_API_TRACE(thread, Atomics, HandleWithUint8);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
uint8_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
if (size == 3) { // the number of parameters is 3
auto result = op((block + indexedPosition), &tag);
auto result = op((block + indexedPosition), arg, ARGS_NUMBER);
return BuiltinsBase::GetTaggedInt(result);
}
JSHandle<JSTaggedValue> newValue = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::FOURTH);
uint8_t newTag = JSTaggedValue::ToUint8(thread, newValue);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
uint8_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
arg[1] = newTag;
auto result = op((block + indexedPosition), arg);
auto result = op((block + indexedPosition), arg, ARGS_NUMBER);
return JSTaggedValue(result);
}
@ -403,18 +403,18 @@ JSTaggedValue BuiltinsAtomics::HandleWithInt8(JSThread *thread, uint32_t size, u
BUILTINS_API_TRACE(thread, Atomics, HandleWithInt8);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int8_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
if (size == 3) { // the number of parameters is 3
auto result = op(reinterpret_cast<int8_t *>(block + indexedPosition), &tag);
auto result = op(reinterpret_cast<int8_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return BuiltinsBase::GetTaggedInt(result);
}
JSHandle<JSTaggedValue> newValue = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::FOURTH);
int8_t newTag = JSTaggedValue::ToInt8(thread, newValue);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int8_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
arg[1] = newTag;
auto result = op(reinterpret_cast<int8_t *>(block + indexedPosition), arg);
auto result = op(reinterpret_cast<int8_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return JSTaggedValue(result);
}
@ -426,18 +426,18 @@ JSTaggedValue BuiltinsAtomics::HandleWithUint16(JSThread *thread, uint32_t size,
BUILTINS_API_TRACE(thread, Atomics, HandleWithUint16);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
uint16_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
if (size == 3) { // the number of parameters is 3
auto result = op(reinterpret_cast<uint16_t *>(block + indexedPosition), &tag);
auto result = op(reinterpret_cast<uint16_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return BuiltinsBase::GetTaggedInt(result);
}
JSHandle<JSTaggedValue> newValue = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::FOURTH);
uint16_t newTag = JSTaggedValue::ToUint16(thread, newValue);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
uint16_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
arg[1] = newTag;
auto result = op(reinterpret_cast<uint16_t *>(block + indexedPosition), arg);
auto result = op(reinterpret_cast<uint16_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return JSTaggedValue(result);
}
@ -449,18 +449,18 @@ JSTaggedValue BuiltinsAtomics::HandleWithInt16(JSThread *thread, uint32_t size,
BUILTINS_API_TRACE(thread, Atomics, HandleWithInt16);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int16_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
if (size == 3) { // the number of parameters is 3
auto result = op(reinterpret_cast<int16_t *>(block + indexedPosition), &tag);
auto result = op(reinterpret_cast<int16_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return BuiltinsBase::GetTaggedInt(result);
}
JSHandle<JSTaggedValue> newValue = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::FOURTH);
int16_t newTag = JSTaggedValue::ToInt16(thread, newValue);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int16_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
arg[1] = newTag;
auto result = op(reinterpret_cast<int16_t *>(block + indexedPosition), arg);
auto result = op(reinterpret_cast<int16_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return JSTaggedValue(result);
}
@ -472,18 +472,18 @@ JSTaggedValue BuiltinsAtomics::HandleWithUint32(JSThread *thread, uint32_t size,
BUILTINS_API_TRACE(thread, Atomics, HandleWithUint32);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
uint32_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
if (size == 3) { // the number of parameters is 3
auto result = op(reinterpret_cast<uint32_t *>(block + indexedPosition), &tag);
auto result = op(reinterpret_cast<uint32_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return JSTaggedValue(result);
}
JSHandle<JSTaggedValue> newValue = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::FOURTH);
uint32_t newTag = JSTaggedValue::ToUint32(thread, newValue);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
uint32_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
arg[1] = newTag;
auto result = op(reinterpret_cast<uint32_t *>(block + indexedPosition), arg);
auto result = op(reinterpret_cast<uint32_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return JSTaggedValue(result);
}
@ -495,18 +495,18 @@ JSTaggedValue BuiltinsAtomics::HandleWithInt32(JSThread *thread, uint32_t size,
BUILTINS_API_TRACE(thread, Atomics, HandleWithInt32);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
if (size == 3) { // the number of parameters is 3
auto result = op(reinterpret_cast<int32_t *>(block + indexedPosition), &tag);
auto result = op(reinterpret_cast<int32_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return BuiltinsBase::GetTaggedInt(result);
}
JSHandle<JSTaggedValue> newValue = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::FOURTH);
int32_t newTag = JSTaggedValue::ToInt32(thread, newValue);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
arg[1] = newTag;
auto result = op(reinterpret_cast<int32_t *>(block + indexedPosition), arg);
auto result = op(reinterpret_cast<int32_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return JSTaggedValue(result);
}
@ -520,8 +520,10 @@ JSTaggedValue BuiltinsAtomics::HandleWithBigInt64(JSThread *thread, uint32_t siz
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int64_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
if (size == 3) { // the number of parameters is 3
auto result = op(reinterpret_cast<int64_t *>(block + indexedPosition), &tag);
auto result = op(reinterpret_cast<int64_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return BigInt::Int64ToBigInt(thread, result).GetTaggedValue();
}
JSHandle<JSTaggedValue> newValue = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::FOURTH);
@ -530,10 +532,8 @@ JSTaggedValue BuiltinsAtomics::HandleWithBigInt64(JSThread *thread, uint32_t siz
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int64_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
arg[1] = newVal;
auto result = op(reinterpret_cast<int64_t *>(block + indexedPosition), arg);
auto result = op(reinterpret_cast<int64_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return BigInt::Int64ToBigInt(thread, result).GetTaggedValue();
}
@ -547,8 +547,10 @@ JSTaggedValue BuiltinsAtomics::HandleWithBigUint64(JSThread *thread, uint32_t si
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
uint64_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
if (size == 3) { // the number of parameters is 3
auto result = op(reinterpret_cast<uint64_t *>(block + indexedPosition), &tag);
auto result = op(reinterpret_cast<uint64_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return BigInt::Uint64ToBigInt(thread, result).GetTaggedValue();
}
JSHandle<JSTaggedValue> newValue = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::FOURTH);
@ -557,10 +559,8 @@ JSTaggedValue BuiltinsAtomics::HandleWithBigUint64(JSThread *thread, uint32_t si
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle<JSTypedArray>::Cast(GetCallArg(argv, 0)));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
uint64_t arg[ARGS_NUMBER] = {0};
arg[0] = tag;
arg[1] = newVal;
auto result = op(reinterpret_cast<uint64_t *>(block + indexedPosition), arg);
auto result = op(reinterpret_cast<uint64_t *>(block + indexedPosition), arg, ARGS_NUMBER);
return BigInt::Uint64ToBigInt(thread, result).GetTaggedValue();
}

View File

@ -186,7 +186,7 @@ JSTaggedValue ContainersStack::ForEach(EcmaRuntimeCallInfo *argv)
}
JSHandle<JSAPIStack> stack = JSHandle<JSAPIStack>::Cast(thisHandle);
uint32_t len = stack->GetSize();
int32_t len = stack->GetSize();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> callbackFnHandle = GetCallArg(argv, 0);
@ -202,7 +202,8 @@ JSTaggedValue ContainersStack::ForEach(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisArgHandle = GetCallArg(argv, 1);
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
uint32_t k = 0;
while (k < len + 1) {
uint32_t actLen = static_cast<uint32_t>(len + 1);
while (k < actLen) {
JSTaggedValue kValue = stack->Get(k);
EcmaRuntimeCallInfo *info =
EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, 3); // 3:three args
@ -254,7 +255,7 @@ JSTaggedValue ContainersStack::GetLength(EcmaRuntimeCallInfo *argv)
}
}
uint32_t len = (JSHandle<JSAPIStack>::Cast(self))->GetSize();
int32_t len = (JSHandle<JSAPIStack>::Cast(self))->GetSize();
return JSTaggedValue(len + 1);
}
} // namespace panda::ecmascript::containers

View File

@ -57,12 +57,12 @@ public:
prev_ = node;
}
int32_t GetIndex() const
uint32_t GetIndex() const
{
return index_;
}
void SetIndex(int32_t index)
void SetIndex(uint32_t index)
{
index_ = index;
}
@ -108,7 +108,7 @@ private:
JSTaggedType obj_;
Node *next_ {nullptr};
Node *prev_ {nullptr};
int32_t index_ {-1};
uint32_t index_ {0};
bool isUsing_ {false};
bool isWeak_ {false};
};
@ -226,7 +226,7 @@ public:
NodeList()
{
bool isWeak = std::is_same<T, WeakNode>::value;
for (int i = 0; i < GLOBAL_BLOCK_SIZE; i++) {
for (uint32_t i = 0; i < GLOBAL_BLOCK_SIZE; i++) {
nodeList_[i].SetIndex(i);
nodeList_[i].SetWeak(isWeak);
}
@ -378,11 +378,11 @@ public:
}
private:
static const int32_t GLOBAL_BLOCK_SIZE = 256;
static const uint32_t GLOBAL_BLOCK_SIZE = 256;
T nodeList_[GLOBAL_BLOCK_SIZE]; // all
T *freeList_ {nullptr}; // dispose node
T *usedList_ {nullptr}; // usage node
int32_t index_ {0};
uint32_t index_ {0};
NodeList<T> *next_ {nullptr};
NodeList<T> *prev_ {nullptr};
NodeList<T> *freeNext_ {nullptr};

View File

@ -150,10 +150,8 @@ bool RegExpExecutor::ExecuteInternal(const DynChunk &byteCode, uint32_t pcEnd)
while (stateStackLen_ > ahead) {
PopRegExpState(isNegative);
}
if (isNegative) {
if (MatchFailed(false)) {
return false;
}
if (isNegative && MatchFailed(false)) {
return false;
}
break;
}

View File

@ -65,11 +65,11 @@ public:
return EcmaStringAccessor::StringsAreEqual(nameString, otherString);
}
static inline int Hash(const JSTaggedValue &key)
static inline uint32_t Hash(const JSTaggedValue &key)
{
ASSERT(key.IsString());
EcmaString *nameStr = static_cast<EcmaString *>(key.GetTaggedObject());
return static_cast<int>(EcmaStringAccessor(nameStr).GetHashcode());
return EcmaStringAccessor(nameStr).GetHashcode();
}
static const int DEFAULT_ELEMENTS_NUMBER = 64;