提交 d0d51b4a 编写于 作者: O openharmony_ci 提交者: Gitee

!393 feat: 支持Lms轻量级地址消毒

Merge pull request !393 from LiteOS/lms
......@@ -355,6 +355,9 @@ config PLATFORM_EXC
######################### config options of trace #########################
source "components/trace/Kconfig"
######################### config options of lms #########################
source "components/lms/Kconfig"
endmenu
######################### config options of lib ########################
......
......@@ -37,6 +37,7 @@ group("components") {
"dynlink",
"exchook",
"fs",
"lms",
"net",
"power",
"shell",
......@@ -56,5 +57,6 @@ config("public") {
"power:public",
"shell:public",
"trace:public",
"lms:public",
]
}
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_m/liteos.gni")
module_switch = defined(LOSCFG_KERNEL_LMS)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"lms_libc.c",
"los_lms.c",
]
}
config("public") {
include_dirs = [ "." ]
}
config KERNEL_LMS
bool "Enable Lite Memory Sanitizer"
default n
depends on KERNEL_EXTKERNEL && DEBUG_VERSION && KERNEL_BACKTRACE
help
Select y to build LiteOS with memory sanitizer.
config LMS_MAX_RECORD_POOL_NUM
int "Lms check pool max num"
default 50
depends on KERNEL_LMS
help
The Max num of lms check pool
config LMS_LOAD_CHECK
bool "Enable lms read check"
default y
depends on KERNEL_LMS
help
Select y to enable read check.
config LMS_STORE_CHECK
bool "Enable lms write check"
default y
depends on KERNEL_LMS
help
Select y to enable write check.
config LMS_CHECK_STRICT
bool "Enable lms strict check, byte-by-byte"
default n
depends on KERNEL_LMS
help
Select y to enable byte-by-byte check in lms
config LMS_LIBC_FULL_CHECK
bool "Enable libc all function do lms check"
default n
depends on KERNEL_LMS
help
Select y to enable libc full check
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "string.h"
#include "los_lms_pri.h"
#undef memset
void *memset(void *addr, int c, size_t len)
{
__asan_storeN_noabort((UINTPTR)addr, len);
return __memset(addr, c, len);
}
#undef memmove
void *memmove(void *dest, const void *src, size_t len)
{
__asan_loadN_noabort((UINTPTR)src, len);
__asan_storeN_noabort((UINTPTR)dest, len);
return __memmove(dest, src, len);
}
#undef memcpy
void *memcpy(void *dest, const void *src, size_t len)
{
__asan_loadN_noabort((UINTPTR)src, len);
__asan_storeN_noabort((UINTPTR)dest, len);
return __memcpy(dest, src, len);
}
#undef strcat
char *strcat (char *s, const char *append)
{
if ((s == NULL) || (append == NULL)) {
return NULL;
}
CHAR *end = s;
size_t len = strlen(append);
for (; *end != '\0'; ++end) {
}
__asan_storeN_noabort((UINTPTR)end, len + 1);
__asan_loadN_noabort((UINTPTR)append, len + 1);
return __strcat(s, append);
}
#undef strcpy
char *strcpy(char *dest, const char *src)
{
if ((dest == NULL) || (src == NULL)) {
return NULL;
}
size_t len = strlen(src);
__asan_storeN_noabort((UINTPTR)dest, len + 1);
__asan_loadN_noabort((UINTPTR)src, len + 1);
return __strcpy(dest, src);
}
#undef strncat
char *strncat(char *dest, const char *src, size_t n)
{
if ((dest == NULL) || (src == NULL)) {
return NULL;
}
CHAR *end = dest;
size_t len = strlen(src);
size_t size = len > n ? n : len;
for (; *end != '\0'; ++end) {
}
__asan_storeN_noabort((UINTPTR)end, size + 1);
__asan_loadN_noabort((UINTPTR)src, size + 1);
return __strncat(dest, src, n);
}
#undef strncpy
char *strncpy(char *dest, const char *src, size_t n)
{
if ((dest == NULL) || (src == NULL)) {
return NULL;
}
size_t len = strlen(src);
size_t size = len > n ? n : len;
__asan_storeN_noabort((UINTPTR)dest, n);
__asan_loadN_noabort((UINTPTR)src, size + 1);
return __strncpy(dest, src, n);
}
此差异已折叠。
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_LMS_H
#define _LOS_LMS_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_KERNEL_LMS
UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size);
VOID LOS_LmsCheckPoolDel(const VOID *pool);
VOID LOS_LmsAddrProtect(UINTPTR addrStart, UINTPTR addrEnd);
VOID LOS_LmsAddrDisableProtect(UINTPTR addrStart, UINTPTR addrEnd);
#endif /* LOSCFG_KERNEL_LMS */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_LMS_H */
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_LMS_PRI_H
#define _LOS_LMS_PRI_H
#include "los_lms.h"
#include "los_compiler.h"
#include "los_list.h"
#include "securec.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define COMMON_ERRMODE 3
#define FREE_ERRORMODE 2
#define STORE_ERRMODE 1
#define LOAD_ERRMODE 0
#define SANITIZER_INTERFACE_ATTRIBUTE
#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
#define LMS_SHADOW_BITS_PER_CELL 2
#define LMS_MEM_BYTES_PER_SHADOW_CELL 4
#define LMS_SHADOW_U8_CELL_NUM 4
#define LMS_SHADOW_U8_REFER_BYTES 16
#define LMS_POOL_RESIZE(size) ((size) / (LMS_SHADOW_U8_REFER_BYTES + 1) * LMS_SHADOW_U8_REFER_BYTES)
#define LMS_ADDR_ALIGN(p) (((UINTPTR)(p) + sizeof(UINTPTR) - 1) & ~((UINTPTR)(sizeof(UINTPTR) - 1)))
#define LMS_SHADOW_ACCESSABLE 0x00
#define LMS_SHADOW_AFTERFREE 0x03
#define LMS_SHADOW_REDZONE 0x02
#define LMS_SHADOW_PAINT 0x01
#define LMS_SHADOW_MASK 0x03
#define LMS_SHADOW_ACCESSABLE_U8 0x00
#define LMS_SHADOW_AFTERFREE_U8 0xFF
#define LMS_SHADOW_REDZONE_U8 0xAA
#define LMS_SHADOW_MASK_U8 0xFF
#define LMS_SHADOW_PAINT_U8 0x55
#define MEM_REGION_SIZE_1 1
#define MEM_REGION_SIZE_2 2
#define MEM_REGION_SIZE_4 4
#define MEM_REGION_SIZE_8 8
#define MEM_REGION_SIZE_16 16
typedef struct {
LOS_DL_LIST node;
UINT32 used;
UINTPTR poolAddr;
UINT32 poolSize;
UINTPTR shadowStart;
UINT32 shadowSize;
} LmsMemListNode;
typedef struct {
UINTPTR memAddr;
UINTPTR shadowAddr;
UINT32 shadowOffset;
UINT32 shadowValue;
} LmsAddrInfo;
typedef struct {
UINT32 (*init)(const VOID *pool, UINT32 size);
VOID (*mallocMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
VOID (*freeMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
VOID (*simpleMark)(UINTPTR startAddr, UINTPTR endAddr, UINT32 value);
VOID (*check)(UINTPTR checkAddr, BOOL isFreeCheck);
} LmsHook;
extern LmsHook* g_lms;
VOID OsLmsInit(VOID);
VOID OsLmsCheckValid(UINTPTR checkAddr, BOOL isFreeCheck);
VOID OsLmsLosMallocMark(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
VOID OsLmsLosFreeMark(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
VOID OsLmsSimpleMark(UINTPTR startAddr, UINTPTR endAddr, UINT32 value);
VOID OsLmsPrintPoolListInfo(VOID);
VOID OsLmsReportError(UINTPTR p, UINT32 size, UINT32 errMod);
VOID CheckValid(const CHAR *dest, const CHAR *src);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store1_noabort(UINTPTR p);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store4_noabort(UINTPTR p);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load4_noabort(UINTPTR p);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load1_noabort(UINTPTR p);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_loadN_noabort(UINTPTR p, UINT32 size);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_storeN_noabort(UINTPTR p, UINT32 size);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store2_noabort(UINTPTR p);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load2_noabort(UINTPTR p);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store8_noabort(UINTPTR p);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load8_noabort(UINTPTR p);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load16_noabort(UINTPTR p);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store16_noabort(UINTPTR p);
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_handle_no_return(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_LMS_PRI_H */
\ No newline at end of file
......@@ -33,7 +33,21 @@ import("//third_party/bounds_checking_function/libsec_src.gni")
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = libsec_sources
if (defined(LOSCFG_KERNEL_LMS)) {
if ("$ohos_build_compiler" == "gcc") {
cflags_c = [ "-fsanitize=kernel-address" ]
} else {
cflags_c = [
"-fsanitize=kernel-address",
"-mllvm",
"-asan-instrumentation-with-call-threshold=0",
"-mllvm",
"-asan-stack=0",
"-mllvm",
"-asan-globals=0",
]
}
}
public_configs = [ ":public" ]
}
......
......@@ -66,6 +66,10 @@
#include "los_dynlink.h"
#endif
#ifdef LOSCFG_KERNEL_LMS
#include "los_lms_pri.h"
#endif
/*****************************************************************************
Function : LOS_Reboot
Description : system exception, die in here, wait for watchdog.
......@@ -125,6 +129,10 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
#endif
OsRegister();
#ifdef LOSCFG_KERNEL_LMS
OsLmsInit();
#endif
ret = OsMemSystemInit();
if (ret != LOS_OK) {
PRINT_ERR("OsMemSystemInit error %d\n", ret);
......
......@@ -37,7 +37,9 @@
#include "los_hook.h"
#include "los_interrupt.h"
#include "los_task.h"
#ifdef LOSCFG_KERNEL_LMS
#include "los_lms_pri.h"
#endif
/* Used to cut non-essential functions. */
#define OS_MEM_EXPAND_ENABLE 0
......@@ -534,7 +536,7 @@ RETRY:
OsMemFreeNodeAdd(pool, (struct OsMemFreeNodeHead *)newNode);
endNode = OS_MEM_END_NODE(newNode, size);
(VOID)memset_s(endNode, sizeof(*endNode), 0, sizeof(*endNode));
(VOID)memset(endNode, 0, sizeof(*endNode));
endNode->ptr.next = NULL;
OS_MEM_SET_MAGIC(endNode);
OsMemSentinelNodeSet(endNode, NULL, 0);
......@@ -553,6 +555,71 @@ VOID LOS_MemExpandEnable(VOID *pool)
}
#endif
#ifdef LOSCFG_KERNEL_LMS
STATIC INLINE VOID OsLmsFirstNodeMark(VOID *pool, struct OsMemNodeHead *node)
{
if (g_lms == NULL) {
return;
}
g_lms->simpleMark((UINTPTR)pool, (UINTPTR)node, LMS_SHADOW_PAINT_U8);
g_lms->simpleMark((UINTPTR)node, (UINTPTR)node + OS_MEM_NODE_HEAD_SIZE, LMS_SHADOW_REDZONE_U8);
g_lms->simpleMark((UINTPTR)OS_MEM_NEXT_NODE(node), (UINTPTR)OS_MEM_NEXT_NODE(node) + OS_MEM_NODE_HEAD_SIZE,
LMS_SHADOW_REDZONE_U8);
g_lms->simpleMark((UINTPTR)node + OS_MEM_NODE_HEAD_SIZE, (UINTPTR)OS_MEM_NEXT_NODE(node),
LMS_SHADOW_AFTERFREE_U8);
}
STATIC INLINE VOID OsLmsAllocAlignMark(VOID *ptr, VOID *alignedPtr, UINT32 size)
{
struct OsMemNodeHead *allocNode = NULL;
if ((g_lms == NULL) || (ptr == NULL)) {
return;
}
allocNode = (struct OsMemNodeHead *)((struct OsMemUsedNodeHead *)ptr - 1);
if (ptr != alignedPtr) {
g_lms->simpleMark((UINTPTR)ptr, (UINTPTR)ptr + sizeof(UINT32), LMS_SHADOW_PAINT_U8);
g_lms->simpleMark((UINTPTR)ptr + sizeof(UINT32), (UINTPTR)alignedPtr, LMS_SHADOW_REDZONE_U8);
}
/* mark remining as redzone */
g_lms->simpleMark(LMS_ADDR_ALIGN((UINTPTR)alignedPtr + size), (UINTPTR)OS_MEM_NEXT_NODE(allocNode),
LMS_SHADOW_REDZONE_U8);
}
STATIC INLINE VOID OsLmsReallocMergeNodeMark(struct OsMemNodeHead *node)
{
if (g_lms == NULL) {
return;
}
g_lms->simpleMark((UINTPTR)node + OS_MEM_NODE_HEAD_SIZE, (UINTPTR)OS_MEM_NEXT_NODE(node),
LMS_SHADOW_ACCESSABLE_U8);
}
STATIC INLINE VOID OsLmsReallocSplitNodeMark(struct OsMemNodeHead *node)
{
if (g_lms == NULL) {
return;
}
/* mark next node */
g_lms->simpleMark((UINTPTR)OS_MEM_NEXT_NODE(node),
(UINTPTR)OS_MEM_NEXT_NODE(node) + OS_MEM_NODE_HEAD_SIZE, LMS_SHADOW_REDZONE_U8);
g_lms->simpleMark((UINTPTR)OS_MEM_NEXT_NODE(node) + OS_MEM_NODE_HEAD_SIZE,
(UINTPTR)OS_MEM_NEXT_NODE(OS_MEM_NEXT_NODE(node)), LMS_SHADOW_AFTERFREE_U8);
}
STATIC INLINE VOID OsLmsReallocResizeMark(struct OsMemNodeHead *node, UINT32 resize)
{
if (g_lms == NULL) {
return;
}
/* mark remaining as redzone */
g_lms->simpleMark((UINTPTR)node + resize, (UINTPTR)OS_MEM_NEXT_NODE(node), LMS_SHADOW_REDZONE_U8);
}
#endif
#if (LOSCFG_MEM_LEAKCHECK == 1)
struct OsMemLeakCheckInfo {
struct OsMemNodeHead *node;
......@@ -568,7 +635,7 @@ STATIC INLINE VOID OsMemLeakCheckInfoRecord(struct OsMemNodeHead *node)
if (!OS_MEM_NODE_GET_LEAK_FLAG(node->sizeAndFlag)) {
info->node = node;
(VOID)memcpy_s(info->linkReg, sizeof(info->linkReg), node->linkReg, sizeof(node->linkReg));
(VOID)memcpy(info->linkReg, node->linkReg, sizeof(node->linkReg));
OS_MEM_NODE_SET_LEAK_FLAG(node->sizeAndFlag);
g_leakCheckRecordCnt++;
if (g_leakCheckRecordCnt >= LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM) {
......@@ -579,14 +646,13 @@ STATIC INLINE VOID OsMemLeakCheckInfoRecord(struct OsMemNodeHead *node)
STATIC INLINE VOID OsMemLeakCheckInit(VOID)
{
(VOID)memset_s(g_leakCheckRecord, sizeof(struct OsMemLeakCheckInfo) * LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM,
0, sizeof(struct OsMemLeakCheckInfo) * LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM);
(VOID)memset(g_leakCheckRecord, 0, sizeof(struct OsMemLeakCheckInfo) * LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM);
g_leakCheckRecordCnt = 0;
}
STATIC INLINE VOID OsMemLinkRegisterRecord(struct OsMemNodeHead *node)
{
(VOID)memset_s(node->linkReg, sizeof(node->linkReg), 0, sizeof(node->linkReg));
(VOID)memset(node->linkReg, 0, sizeof(node->linkReg));
OsBackTraceHookCall(node->linkReg, LOSCFG_MEM_RECORD_LR_CNT, LOSCFG_MEM_OMIT_LR_CNT, 0);
}
......@@ -840,6 +906,12 @@ STATIC INLINE VOID *OsMemCreateUsedNode(VOID *addr)
OsMemNodeSetTaskID(node);
#endif
#ifdef LOSCFG_KERNEL_LMS
struct OsMemNodeHead *newNode = (struct OsMemNodeHead *)node;
if (g_lms != NULL) {
g_lms->mallocMark(newNode, OS_MEM_NEXT_NODE(newNode), OS_MEM_NODE_HEAD_SIZE);
}
#endif
return node + 1;
}
......@@ -848,8 +920,18 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
struct OsMemNodeHead *newNode = NULL;
struct OsMemNodeHead *endNode = NULL;
(VOID)memset_s(poolHead, sizeof(struct OsMemPoolHead), 0, sizeof(struct OsMemPoolHead));
#ifdef LOSCFG_KERNEL_LMS
UINT32 resize = 0;
if (g_lms != NULL) {
/*
* resize == 0, shadow memory init failed, no shadow memory for this pool, set poolSize as original size.
* resize != 0, shadow memory init successful, set poolSize as resize.
*/
resize = g_lms->init(pool, size);
size = (resize == 0) ? size : resize;
}
#endif
(VOID)memset(poolHead, 0, sizeof(struct OsMemPoolHead));
poolHead->info.pool = pool;
poolHead->info.totalSize = size;
......@@ -878,13 +960,18 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
poolHead->info.waterLine = poolHead->info.curUsedSize;
#endif
#ifdef LOSCFG_KERNEL_LMS
if (resize != 0) {
OsLmsFirstNodeMark(pool, newNode);
}
#endif
return LOS_OK;
}
#if (LOSCFG_MEM_MUL_POOL == 1)
STATIC VOID OsMemPoolDeinit(VOID *pool)
{
(VOID)memset_s(pool, sizeof(struct OsMemPoolHead), 0, sizeof(struct OsMemPoolHead));
(VOID)memset(pool, 0, sizeof(struct OsMemPoolHead));
}
STATIC UINT32 OsMemPoolAdd(VOID *pool, UINT32 size)
......@@ -1118,6 +1205,9 @@ VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary)
ptr = OsMemAlloc(pool, useSize, intSave);
alignedPtr = (VOID *)OS_MEM_ALIGN(ptr, boundary);
if (ptr == alignedPtr) {
#ifdef LOSCFG_KERNEL_LMS
OsLmsAllocAlignMark(ptr, alignedPtr, size);
#endif
break;
}
......@@ -1127,6 +1217,9 @@ VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary)
OS_MEM_NODE_SET_ALIGNED_FLAG(allocNode->header.sizeAndFlag);
OS_MEM_SET_GAPSIZE_ALIGNED_FLAG(gapSize);
*(UINT32 *)((UINTPTR)alignedPtr - sizeof(gapSize)) = gapSize;
#ifdef LOSCFG_KERNEL_LMS
OsLmsAllocAlignMark(ptr, alignedPtr, size);
#endif
ptr = alignedPtr;
} while (0);
MEM_UNLOCK(poolHead, intSave);
......@@ -1251,6 +1344,13 @@ STATIC INLINE UINT32 OsMemFree(struct OsMemPoolHead *pool, struct OsMemNodeHead
node->sizeAndFlag = OS_MEM_NODE_GET_SIZE(node->sizeAndFlag);
#if (LOSCFG_MEM_LEAKCHECK == 1)
OsMemLinkRegisterRecord(node);
#endif
#ifdef LOSCFG_KERNEL_LMS
struct OsMemNodeHead *nextNodeBackup = OS_MEM_NEXT_NODE(node);
struct OsMemNodeHead *curNodeBackup = node;
if (g_lms != NULL) {
g_lms->check((UINTPTR)node + OS_MEM_NODE_HEAD_SIZE, TRUE);
}
#endif
struct OsMemNodeHead *preNode = node->ptr.prev; /* merage preNode */
if ((preNode != NULL) && !OS_MEM_NODE_GET_USED_FLAG(preNode->sizeAndFlag)) {
......@@ -1278,7 +1378,11 @@ STATIC INLINE UINT32 OsMemFree(struct OsMemPoolHead *pool, struct OsMemNodeHead
#endif
OsMemFreeNodeAdd(pool, (struct OsMemFreeNodeHead *)node);
#ifdef LOSCFG_KERNEL_LMS
if (g_lms != NULL) {
g_lms->freeMark(curNodeBackup, nextNodeBackup, OS_MEM_NODE_HEAD_SIZE);
}
#endif
return ret;
}
......@@ -1342,6 +1446,11 @@ STATIC INLINE VOID OsMemReAllocSmaller(VOID *pool, UINT32 allocSize, struct OsMe
OsMemSplitNode(pool, node, allocSize);
#if (LOSCFG_MEM_WATERLINE == 1)
poolInfo->info.curUsedSize -= nodeSize - allocSize;
#endif
#ifdef LOSCFG_KERNEL_LMS
OsLmsReallocSplitNodeMark(node);
} else {
OsLmsReallocResizeMark(node, allocSize);
#endif
}
OS_MEM_NODE_SET_USED_FLAG(node->sizeAndFlag);
......@@ -1356,8 +1465,16 @@ STATIC INLINE VOID OsMemMergeNodeForReAllocBigger(VOID *pool, UINT32 allocSize,
node->sizeAndFlag = nodeSize;
OsMemFreeNodeDelete(pool, (struct OsMemFreeNodeHead *)nextNode);
OsMemMergeNode(nextNode);
#ifdef LOSCFG_KERNEL_LMS
OsLmsReallocMergeNodeMark(node);
#endif
if ((allocSize + OS_MEM_MIN_LEFT_SIZE) <= node->sizeAndFlag) {
OsMemSplitNode(pool, node, allocSize);
#ifdef LOSCFG_KERNEL_LMS
OsLmsReallocSplitNodeMark(node);
} else {
OsLmsReallocResizeMark(node, allocSize);
#endif
}
OS_MEM_NODE_SET_USED_FLAG(node->sizeAndFlag);
OsMemWaterUsedRecord((struct OsMemPoolHead *)pool, node->sizeAndFlag - nodeSize);
......@@ -1752,10 +1869,8 @@ struct OsMemIntegrityCheckInfo g_integrityCheckRecord = {0};
STATIC INLINE VOID OsMemCheckInfoRecord(const struct OsMemNodeHead *errNode,
const struct OsMemNodeHead *preNode)
{
(VOID)memcpy_s(&g_integrityCheckRecord.preNode, sizeof(struct OsMemNodeHead),
preNode, sizeof(struct OsMemNodeHead));
(VOID)memcpy_s(&g_integrityCheckRecord.errNode, sizeof(struct OsMemNodeHead),
errNode, sizeof(struct OsMemNodeHead));
(VOID)memcpy(&g_integrityCheckRecord.preNode, preNode, sizeof(struct OsMemNodeHead));
(VOID)memcpy(&g_integrityCheckRecord.errNode, errNode, sizeof(struct OsMemNodeHead));
}
STATIC VOID OsMemIntegrityCheckError(struct OsMemPoolHead *pool,
......@@ -1891,7 +2006,7 @@ UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
return LOS_NOK;
}
(VOID)memset_s(poolStatus, sizeof(LOS_MEM_POOL_STATUS), 0, sizeof(LOS_MEM_POOL_STATUS));
(VOID)memset(poolStatus, 0, sizeof(LOS_MEM_POOL_STATUS));
OsAllMemNodeDoHandle(pool, OsMemNodeInfoGetHandle, (VOID *)poolStatus);
......@@ -2054,9 +2169,19 @@ STATIC INLINE VOID OsMemMulRegionsLink(struct OsMemPoolHead *poolHead, VOID *las
curStartAddress = memRegion->startAddress;
curLength = memRegion->length;
#ifdef LOSCFG_KERNEL_LMS
UINT32 resize = 0;
if (g_lms != NULL) {
/*
* resize == 0, shadow memory init failed, no shadow memory for this pool, set poolSize as original size.
* resize != 0, shadow memory init successful, set poolSize as resize.
*/
resize = g_lms->init(curStartAddress, curLength);
curLength = (resize == 0) ? curLength : resize;
}
#endif
// mark the gap between two regions as one used node
gapSize = (UINT8 *)(curStartAddress) - ((UINT8 *)(lastStartAddress) + lastLength);
gapSize = (UINT8 *)(curStartAddress) - ((UINT8 *)(poolHead) + poolHead->info.totalSize);
lastEndNode->sizeAndFlag = gapSize + OS_MEM_NODE_HEAD_SIZE;
OS_MEM_SET_MAGIC(lastEndNode);
OS_MEM_NODE_SET_USED_FLAG(lastEndNode->sizeAndFlag);
......@@ -2122,7 +2247,7 @@ UINT32 LOS_MemRegionsAdd(VOID *pool, const LosMemRegion *const memRegions, UINT3
}
firstFreeNode = OS_MEM_FIRST_NODE(lastStartAddress);
lastEndNode = OS_MEM_END_NODE(lastStartAddress, lastLength);
lastEndNode = OS_MEM_END_NODE(lastStartAddress, poolHead->info.totalSize);
/* traverse the rest memory regions, and initialize them as free nodes and link together */
while (regionCount < memRegionCount) {
curStartAddress = memRegion->startAddress;
......@@ -2131,7 +2256,7 @@ UINT32 LOS_MemRegionsAdd(VOID *pool, const LosMemRegion *const memRegions, UINT3
OsMemMulRegionsLink(poolHead, lastStartAddress, lastLength, lastEndNode, memRegion);
lastStartAddress = curStartAddress;
lastLength = curLength;
lastEndNode = OS_MEM_END_NODE(curStartAddress, curLength);
lastEndNode = OS_MEM_END_NODE(poolHead, poolHead->info.totalSize);
memRegion++;
regionCount++;
}
......@@ -2163,7 +2288,7 @@ STATIC VOID OsMemExcInfoGetSub(struct OsMemPoolHead *pool, MemInfoCB *memExcInfo
UINT32 taskID = OS_TASK_ERRORID;
UINT32 intSave = 0;
(VOID)memset_s(memExcInfo, sizeof(MemInfoCB), 0, sizeof(MemInfoCB));
(VOID)memset(memExcInfo, 0, sizeof(MemInfoCB));
MEM_LOCK(pool, intSave);
memExcInfo->type = MEM_MANG_MEMORY;
......
......@@ -69,6 +69,9 @@ group("testsuites") {
if (defined(LOSCFG_DYNLINK)) {
deps += [ "sample/kernel/dynlink:test_dynlink" ]
}
if (defined(LOSCFG_KERNEL_LMS)) {
deps += [ "sample/kernel/lms:test_lms" ]
}
if (!module_switch) {
deps = []
}
......
......@@ -162,6 +162,7 @@ typedef enum {
#endif
TEST_DRIVERBASE,
TEST_DYNLINK,
TEST_LMS,
} LiteOS_test_module;
typedef enum {
......
......@@ -85,6 +85,7 @@ extern "C" {
#define LOS_KERNEL_DYNLINK_TEST 0
#define LOS_KERNEL_TICKLESS_TEST 0
#define LOS_KERNEL_PM_TEST 1
#define LOS_KERNEL_LMS_TEST 0
#define LITEOS_CMSIS_TEST 0
#define LOS_CMSIS2_CORE_TASK_TEST 0
......
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static_library("test_lms") {
sources = [
"It_los_lms.c",
"It_los_lms_001.c",
"It_los_lms_002.c",
"It_los_lms_003.c",
"It_los_lms_004.c",
"It_los_lms_005.c",
"It_los_lms_006.c",
"It_los_lms_007.c",
"It_los_lms_008.c",
"It_los_lms_009.c",
"It_los_lms_010.c",
"It_los_lms_011.c",
"It_los_lms_012.c",
"It_los_lms_013.c",
"It_los_lms_014.c",
"It_los_lms_015.c",
"It_los_lms_016.c",
"It_los_lms_017.c",
"It_los_lms_018.c",
"It_los_lms_019.c",
"It_los_lms_020.c",
"It_los_lms_021.c",
"It_los_lms_022.c",
"It_los_lms_023.c",
"It_los_lms_024.c",
]
if ("$ohos_build_compiler_specified" == "gcc") {
cflags_c = [
"-O0",
"-fsanitize=kernel-address",
]
} else {
cflags_c = [
"-O0",
"-fsanitize=kernel-address",
"-mllvm",
"-asan-instrumentation-with-call-threshold=0",
"-mllvm",
"-asan-stack=0",
"-mllvm",
"-asan-globals=0",
]
}
configs += [ "//kernel/liteos_m/testsuites:include" ]
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_los_lms.h"
char g_testLmsPool[2 * PAGE_SIZE];
STATIC VOID testPoolInit(void)
{
UINT32 ret = LOS_MemInit(g_testLmsPool, 2 * PAGE_SIZE);
if (ret != 0) {
PRINT_ERR("%s failed, ret = 0x%x\n", __FUNCTION__, ret);
return;
}
}
VOID ItSuiteLosLms(void)
{
testPoolInit();
ItLosLms001();
ItLosLms002();
ItLosLms003();
ItLosLms004();
ItLosLms005();
ItLosLms006();
ItLosLms007();
ItLosLms008();
ItLosLms009();
ItLosLms010();
ItLosLms011();
ItLosLms012();
ItLosLms013();
ItLosLms014();
ItLosLms015();
ItLosLms016();
ItLosLms017();
ItLosLms018();
ItLosLms019();
ItLosLms020();
ItLosLms021();
ItLosLms022();
ItLosLms023();
ItLosLms024();
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IT_LOS_LMS_H
#define IT_LOS_LMS_H
#include "osTest.h"
#include "los_memory.h"
#include "los_config.h"
#include "iCunit.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define INDEX_MAX 20
#define PAGE_SIZE (0x1000U)
extern char g_testLmsPool[2 * PAGE_SIZE];
VOID ItLosLms001(void);
VOID ItLosLms002(void);
VOID ItLosLms003(void);
VOID ItLosLms004(void);
VOID ItLosLms005(void);
VOID ItLosLms006(void);
VOID ItLosLms007(void);
VOID ItLosLms008(void);
VOID ItLosLms009(void);
VOID ItLosLms010(void);
VOID ItLosLms011(void);
VOID ItLosLms012(void);
VOID ItLosLms013(void);
VOID ItLosLms014(void);
VOID ItLosLms015(void);
VOID ItLosLms016(void);
VOID ItLosLms017(void);
VOID ItLosLms018(void);
VOID ItLosLms019(void);
VOID ItLosLms020(void);
VOID ItLosLms021(void);
VOID ItLosLms022(void);
VOID ItLosLms023(void);
VOID ItLosLms024(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* IT_LOS_LMS_H */
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 i;
char *str = (char*)LOS_MemAlloc(g_testLmsPool, INDEX_MAX);
for (i = 0; i < INDEX_MAX + 1; i++) {
if (i % 4 == 0) {
PRINTK("\n");
}
PRINTK("str[%2d]=0x%2x ", i, str[i]);
}
return LOS_OK;
}
/* LmsTestOsmallocOverflow */
VOID ItLosLms001(void)
{
TEST_ADD_CASE("ItLosLms001", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 boundary;
CHAR *str = NULL;
UINT32 i;
UINT32 size = 20; /* mem size 20 */
for (i = 2; i < 8; i++) { /* boundary loop from 2 to 8 */
boundary = 1 << i;
str = (CHAR *)LOS_MemAllocAlign(m_aucSysMem0, size, boundary);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
PRINTK("str = 0x%x, boundary = %d\n", str, boundary);
PRINTK("0x%x\n", str[size + 1]); /* trigger read overflow at size + 1 */
(VOID)LOS_MemFree(m_aucSysMem0, str);
}
return LOS_OK;
}
/* LmsTestMemAlignOverflow */
VOID ItLosLms002(void)
{
TEST_ADD_CASE("ItLosLms002", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 boundary;
CHAR *str = NULL;
UINT32 i;
UINT32 size = 0x8 + 0x2; /* mem size 0x8 + 0x2 */
for (i = 2; i < 8; i++) { /* boundary loop from 2 to 8 */
boundary = 1 << i;
str = (CHAR *)LOS_MemAllocAlign(m_aucSysMem0, size, boundary);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
PRINTK("str = 0x%x, boundary = %d\n", str, boundary);
PRINTK("0x%x\n", str[size + 1]); /* not trigger read overflow at size + 1 */
PRINTK("0x%x\n", str[size + 2]); /* trigger read overflow at size + 2 */
(VOID)LOS_MemFree(m_aucSysMem0, str);
}
return LOS_OK;
}
/* LmsTestMemAlignOverflow_Not4Align */
VOID ItLosLms003(void)
{
TEST_ADD_CASE("ItLosLms003", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
#define PTR_NUM 100
#define SIZE_NUM 2
CHAR *str[PTR_NUM] = {NULL};
UINT32 size[SIZE_NUM] = {20, 10}; /* mem size 20, 10 */
UINT32 index;
UINT32 i, j, k;
UINT32 boundary;
for (k = 0; k < SIZE_NUM; k++) {
index = 0;
for (j = 0; j < 10; j++) { /* loop 10 times each size */
for (i = 2; i < 8; i++, index++) { /* boundary loop from 2 to 8 */
boundary = 1 << i;
PRINT_DEBUG("size = %d, boundary = %d\n", size[k], boundary);
str[index] = (char *)LOS_MemAllocAlign(m_aucSysMem0, size[k], boundary);
ICUNIT_GOTO_NOT_EQUAL(str[index], NULL, str[index], EXIT);
}
}
for (i = 0; i < index; i++) {
(VOID)LOS_MemFree(m_aucSysMem0, str[i]);
}
}
return LOS_OK;
EXIT:
for (i = 0; i < index; i++) {
(VOID)LOS_MemFree(m_aucSysMem0, str[i]);
}
return LOS_OK;
}
/* LmsTestMemAlignFree */
VOID ItLosLms004(void)
{
TEST_ADD_CASE("ItLosLms004", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 size = 20; /* mem size 20 */
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
PRINT_DEBUG("str = 0x%x\n", str);
(VOID)memset_s(str, size, 0xca, size);
/* oldSize - newsize < OS_MEM_NODE_HEAD_SIZE + OS_MEM_ALIGN_SIZE */
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, size - 4); /* mem size - 4 */
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT);
PRINTK("newPtr = 0x%x\n", newPtr[size - 4]); /* trigger read overflow at size - 4 */
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
return LOS_OK;
EXIT:
(VOID)LOS_MemFree(g_testLmsPool, str);
return LOS_OK;
}
/* LmsTestReallocTest1 */
VOID ItLosLms005(void)
{
TEST_ADD_CASE("ItLosLms005", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 size = 20 * 3; /* mem size 20 * 3 */
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
PRINT_DEBUG("str = 0x%x\n", str);
(VOID)memset_s(str, size, 0xca, size);
/* oldSize - newSize >= OS_MEM_NODE_HEAD_SIZE + OS_MEM_ALIGN_SIZE */
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, size - 32); /* mem size - 32 */
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT);
PRINTK("newPtr = 0x%x\n", newPtr[size - 30]); /* trigger read overflow at size - 30 */
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
return LOS_OK;
EXIT:
(VOID)LOS_MemFree(g_testLmsPool, str);
return LOS_OK;
}
/* LmsTestReallocTest2 */
VOID ItLosLms006(void)
{
TEST_ADD_CASE("ItLosLms006", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 size = 20; /* mem size 20 */
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
PRINT_DEBUG("str = 0x%x\n", str);
CHAR *bigger = (CHAR *)LOS_MemAlloc(g_testLmsPool, size * 3); /* mem size * 3 */
ICUNIT_GOTO_NOT_EQUAL(bigger, NULL, bigger, EXIT);
PRINT_DEBUG("bigger addr = 0x%x, %d\n", bigger, __LINE__);
CHAR *tmp = (CHAR *)LOS_MemAlloc(g_testLmsPool, size); /* do not release */
ICUNIT_GOTO_NOT_EQUAL(tmp, NULL, tmp, EXIT1);
PRINT_DEBUG("tmp addr = 0x%x,%d\n", tmp, __LINE__);
(VOID)LOS_MemFree(g_testLmsPool, bigger);
/* resize < size + next size && split node */
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, size * 2); /* mem size * 2 */
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT2);
PRINTK("0x%x\n", newPtr[size * 2]); /* trigger read overflow at size * 2 */
(VOID)LOS_MemFree(g_testLmsPool, tmp);
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
return LOS_OK;
EXIT:
(VOID)LOS_MemFree(g_testLmsPool, str);
return LOS_OK;
EXIT1:
(VOID)LOS_MemFree(g_testLmsPool, str);
(VOID)LOS_MemFree(g_testLmsPool, bigger);
return LOS_OK;
EXIT2:
(VOID)LOS_MemFree(g_testLmsPool, str);
(VOID)LOS_MemFree(g_testLmsPool, tmp);
return LOS_OK;
}
/* LmsTestReallocTest3 */
VOID ItLosLms007(void)
{
TEST_ADD_CASE("ItLosLms007", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 size = 20; /* mem size 20 */
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
PRINT_DEBUG("str = 0x%x\n", str);
CHAR *bigger = (CHAR *)LOS_MemAlloc(g_testLmsPool, size * 3); /* mem size * 3 */
ICUNIT_GOTO_NOT_EQUAL(bigger, NULL, bigger, EXIT);
PRINT_DEBUG("bigger = 0x%x,%d\n", bigger, __LINE__);
CHAR *tmp = (CHAR *)LOS_MemAlloc(g_testLmsPool, size); /* do not release */
ICUNIT_GOTO_NOT_EQUAL(tmp, NULL, tmp, EXIT1);
PRINT_DEBUG("tmp = 0x%x,%d\n", tmp, __LINE__);
(VOID)LOS_MemFree(g_testLmsPool, bigger);
/* resize < size + next size && not split node */
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, size * 4 + 8); /* mem size * 4 - 8 */
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT2);
PRINT_DEBUG("newPtr = 0x%x,%d\n", newPtr, __LINE__);
PRINTK("0x%x\n", newPtr[size * 4 + 8]); /* trigger read overflow at size * 4 - 8 */
(VOID)LOS_MemFree(g_testLmsPool, tmp);
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
return LOS_OK;
EXIT:
(VOID)LOS_MemFree(g_testLmsPool, str);
return LOS_OK;
EXIT1:
(VOID)LOS_MemFree(g_testLmsPool, str);
(VOID)LOS_MemFree(g_testLmsPool, bigger);
return LOS_OK;
EXIT2:
(VOID)LOS_MemFree(g_testLmsPool, str);
(VOID)LOS_MemFree(g_testLmsPool, tmp);
return LOS_OK;
}
/* LmsTestReallocTest4 */
VOID ItLosLms008(void)
{
TEST_ADD_CASE("ItLosLms008", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 size = 20; /* mem size 20 */
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
PRINT_DEBUG("str = 0x%x,%d\n", str, __LINE__);
CHAR *bigger = (CHAR *)LOS_MemAlloc(g_testLmsPool, size * 3); /* mem size * 3 */
ICUNIT_GOTO_NOT_EQUAL(bigger, NULL, bigger, EXIT);
PRINT_DEBUG("bigger = 0x%x,%d\n", bigger, __LINE__);
CHAR *tmp = (CHAR *)LOS_MemAlloc(g_testLmsPool, size); /* do not release */
ICUNIT_GOTO_NOT_EQUAL(tmp, NULL, tmp, EXIT1);
PRINT_DEBUG("tmp = 0x%x,%d\n", tmp, __LINE__);
(VOID)LOS_MemFree(g_testLmsPool, bigger);
/* resize > size + next size */
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, size * 6); /* mem size * 6 */
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT2);
PRINT_DEBUG("newPtr = 0x%x,%d\n", newPtr, __LINE__);
PRINTK("0x%x\n", newPtr[size * 6]); /* trigger overflow at size * 6 */
(VOID)LOS_MemFree(g_testLmsPool, tmp);
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
return LOS_OK;
EXIT:
(VOID)LOS_MemFree(g_testLmsPool, str);
return LOS_OK;
EXIT1:
(VOID)LOS_MemFree(g_testLmsPool, str);
(VOID)LOS_MemFree(g_testLmsPool, bigger);
return LOS_OK;
EXIT2:
(VOID)LOS_MemFree(g_testLmsPool, str);
(VOID)LOS_MemFree(g_testLmsPool, tmp);
return LOS_OK;
}
/* LmsTestReallocTest5 */
VOID ItLosLms009(void)
{
TEST_ADD_CASE("ItLosLms009", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 size = 20; /* mem size 20 */
CHAR *backStr;
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
PRINT_DEBUG("str = 0x%x,%d\n", str, __LINE__);
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, 0x8+0x2); /* reaSize 0x2 is not 4Align */
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT);
PRINT_DEBUG("newPtr = 0x%x,%d\n", newPtr, __LINE__);
PRINTK("0x%x\n", newPtr[0x8+0x3]); /* not trigger overflow at newPtr[0x3] */
PRINTK("Trigger write overflow\n");
newPtr[0x8+0x4] = 0x01; /* write 0x1,trigger overflow at newPtr[0x4] */
PRINTK("Trigger read overflow\n");
PRINTK("0x%x\n", newPtr[0x8+0x4]); /* trigger read overflow at newPtr[0x4] */
backStr = (CHAR *)(newPtr - 1); /* Add offset -1 */
PRINTK("Trigger back offset write overflow\n");
*backStr = 0x01;
PRINTK("Trigger back offset read overflow\n");
PRINTK("0x%x\n", *backStr); /* trigger overflow */
PRINTK("Trigger read overflow\n"); /* trigger read overflow */
PRINTK("0x%x\n", newPtr[0x8+0x5]); /* trigger overflow at newPtr[0x5] */
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
return LOS_OK;
EXIT:
(VOID)LOS_MemFree(g_testLmsPool, str);
return LOS_OK;
}
/* LmsTestReallocTest6 */
VOID ItLosLms010(void)
{
TEST_ADD_CASE("ItLosLms010", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 i;
char *str = (char*)LOS_MemAlloc(m_aucSysMem0, INDEX_MAX);
for (i = 0; i < INDEX_MAX; i++) {
if (i % 4 == 0) {
PRINTK("\n");
}
PRINTK("str[%2d]=0x%2x ", i, str[i]);
}
LOS_MemFree(m_aucSysMem0, str);
PRINTK("str[%2d]=0x%2x ", 0, str[0]);
return LOS_OK;
}
/* LmsTestUseAfterFree */
VOID ItLosLms011(void)
{
TEST_ADD_CASE("ItLosLms011", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 i;
char *str = (char*)LOS_MemAlloc(m_aucSysMem0, INDEX_MAX);
for (i = 0; i < INDEX_MAX; i++) {
if (i % 4 == 0) {
PRINTK("\n");
}
PRINTK("str[%2d]=0x%2x ", i, str[i]);
}
LOS_MemFree(m_aucSysMem0, str);
LOS_MemFree(m_aucSysMem0, str);
return LOS_OK;
}
/* LmsTestDoubleFree */
VOID ItLosLms012(void)
{
TEST_ADD_CASE("ItLosLms012", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 i;
char str2[INDEX_MAX + 1] = "1234567890abcdefghij";
char *str = (char*)LOS_MemAlloc(m_aucSysMem0, INDEX_MAX);
memcpy(str, str2, INDEX_MAX + 1);
for (i = 0; i < INDEX_MAX + 1; i++) {
if (i % 4 == 0) {
PRINTK("\n");
}
PRINTK("str[%2d]=0x%2x ", i, str[i]);
}
return LOS_OK;
}
/* LmsTestMemcpyOverflow */
VOID ItLosLms013(void)
{
TEST_ADD_CASE("ItLosLms013", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
UINT32 i;
char *str = (char*)LOS_MemAlloc(m_aucSysMem0, INDEX_MAX);
memset(str, 0xca, INDEX_MAX + 1);
for (i = 0; i < INDEX_MAX + 1; i++) {
if (i % 4 == 0) {
PRINTK("\n");
}
PRINTK("str[%2d]=0x%2x ", i, str[i]);
}
return LOS_OK;
}
/* LmsTestMemsetSOverflow */
VOID ItLosLms014(void)
{
TEST_ADD_CASE("ItLosLms014", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
#define SIZEE 100
CHAR src[SIZEE + 1] = {0};
CHAR *p = (CHAR *)LOS_MemAlloc(m_aucSysMem0, SIZEE);
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, 0);
memmove(p, src, SIZEE);
PRINTK("p[0] = %d\n", p[0]);
memmove(p, src, SIZEE + 1); /* trigger overflow */
return LOS_OK;
}
/* LmsTestMemmoveOverflow */
VOID ItLosLms015(void)
{
TEST_ADD_CASE("ItLosLms015", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
CHAR *string = "LMS_TestCase";
CHAR *src;
CHAR *buf;
CHAR *str;
UINT32 ret;
src = LOS_MemAlloc(m_aucSysMem0, strlen(string));
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
buf = LOS_MemAlloc(m_aucSysMem0, (strlen(string) + 10)); /* mem size 10 */
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
str = strcpy(src, string); /* write overflow */
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
(VOID)strcpy(buf, src); /* Check LMS detection information when the strcpy src overflows. */
ret = LOS_MemFree(m_aucSysMem0, buf);
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
ret = LOS_MemFree(m_aucSysMem0, src);
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
return LOS_OK;
}
/* LmsTestStrcpyOverflow */
VOID ItLosLms016(void)
{
TEST_ADD_CASE("ItLosLms016", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
CHAR *string = "LMS_TestCase";
CHAR *src;
CHAR *buf;
CHAR *str;
UINT32 ret;
src = LOS_MemAlloc(m_aucSysMem0, (strlen(string) + 1)); /* mem size 1 */
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
str = strcpy(src, string);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
buf = LOS_MemAlloc(m_aucSysMem0, (strlen(string) + 4)); /* mem size 10 */
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
(VOID)memset(buf, 0, (strlen(string) + 4)); /* memset size 10 */
(VOID)strcat(buf, src); /* no overflows. */
(VOID)strcat(buf, "123"); /* no overflows. */
(VOID)strcat(buf, "4"); /* write overflows. */
ret = LOS_MemFree(m_aucSysMem0, buf);
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
ret = LOS_MemFree(m_aucSysMem0, src);
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
return LOS_OK;
}
/* LmsTestStrcatOverflow */
VOID ItLosLms017(void)
{
TEST_ADD_CASE("ItLosLms017", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
CHAR *src;
CHAR *buf;
src = LOS_MemAlloc(m_aucSysMem0, 9);
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
(VOID)memset(src, 0, 9);
src[0] = 49;
src[1] = 50;
src[2] = 51;
src[3] = 52;
src[4] = 53;
src[5] = 54;
src[6] = 55;
src[7] = 56;
PRINTK("strlen(src) = %d\n", strlen(src));
buf = LOS_MemAlloc(m_aucSysMem0, 7);
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
buf[0] = 0;
strncat(buf, src, 8); /* trigger buf overflow */
buf[0] = 0;
strncat(buf, src, 9); /* trigger buf overflow */
buf[0] = 0;
strncat(buf, src, 20); /* trigger buf overflow */
buf[0] = 0;
strncat(buf, src, 21); /* trigger buf overflow */
PRINTK("\n######%s stop ######\n", __FUNCTION__);
return LOS_OK;
}
/* LmsTestStrncatOverflow */
VOID ItLosLms018(void)
{
TEST_ADD_CASE("ItLosLms018", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
CHAR *src;
CHAR *buf;
src = LOS_MemAlloc(m_aucSysMem0, 9);
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
(VOID)memset(src, 0, 9);
src[0] = 49;
src[1] = 50;
src[2] = 51;
src[3] = 52;
src[4] = 53;
src[5] = 54;
src[6] = 55;
src[7] = 56;
PRINTK("strlen(src) = %d\n", strlen(src));
buf = LOS_MemAlloc(m_aucSysMem0, 20);
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
buf[0] = 0;
(VOID)strncpy(buf, src, 8); /* no trigger overflow */
buf[0] = 0;
(VOID)strncpy(buf, src, 9); /* no trigger overflow */
buf[0] = 0;
(VOID)strncpy(buf, src, 20); /* no trigger overflow */
buf[0] = 0;
(VOID)strncpy(buf, src, 21); /* trigger buf overflow */
return LOS_OK;
}
/* LmsTestStrncpyOverflow */
VOID ItLosLms019(void)
{
TEST_ADD_CASE("ItLosLms019", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
CHAR *p = (CHAR *)LOS_MemAlloc(g_testLmsPool, INDEX_MAX);
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, 0);
memset_s(p, INDEX_MAX, 0, INDEX_MAX + 1);
PRINTK("p[0] = %d\n", p[0]);
memset_s(p, INDEX_MAX + 1, 0, INDEX_MAX + 1); /* trigger overflow */
return LOS_OK;
}
/* LmsTestMemset_sOverflow */
VOID ItLosLms020(void)
{
TEST_ADD_CASE("ItLosLms020", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
CHAR src[INDEX_MAX + 1] = {0};
CHAR *p = (CHAR *)LOS_MemAlloc(g_testLmsPool, INDEX_MAX);
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, 0);
memcpy_s(p, INDEX_MAX, src, INDEX_MAX + 1);
PRINTK("p[0] = %d\n", p[0]);
memcpy_s(p, INDEX_MAX + 1, 0, INDEX_MAX + 1); /* trigger overflow */
return LOS_OK;
}
/* LmsTestMemcpy_sOverflow */
VOID ItLosLms021(void)
{
TEST_ADD_CASE("ItLosLms021", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
CHAR *p = (CHAR *)LOS_MemAlloc(g_testLmsPool, INDEX_MAX);
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, 0);
memmove_s(p, INDEX_MAX, 0, INDEX_MAX + 1);
PRINTK("p[0] = %d\n", p[0]);
memmove_s(p, INDEX_MAX + 1, 0, INDEX_MAX + 1); /* trigger overflow */
return LOS_OK;
}
/* LmsTestMemmove_sOverflow */
VOID ItLosLms022(void)
{
TEST_ADD_CASE("ItLosLms022", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
CHAR *string = "LMS_TestCase";
CHAR *src;
CHAR *buf;
CHAR *str;
UINT32 ret;
src = LOS_MemAlloc(g_testLmsPool, (strlen(string) + 1));
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
PRINTK("%d\n", __LINE__);
(VOID)__memset(src, 0, (strlen(string) + 1));
PRINTK("%d\n", __LINE__);
str = __strcpy(src, string);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
PRINTK("%d\n", __LINE__);
buf = LOS_MemAlloc(g_testLmsPool, 8); /* mem size 8 */
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
buf[7] = '\0'; /* end index 7 */
PRINTK("%d\n", __LINE__);
ret = strcat_s(buf, 100, src); /* Check LMS detection information when the strcat dest max set 100 overflows. */
PRINTK("%d\n", __LINE__);
ret = LOS_MemFree(g_testLmsPool, buf);
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
ret = LOS_MemFree(g_testLmsPool, src);
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
return LOS_OK;
}
/* LmsTestStrcat_sOverflow */
VOID ItLosLms023(void)
{
TEST_ADD_CASE("ItLosLms023", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_lms.h"
static UINT32 TestCase(VOID)
{
CHAR *string = "LMS_TestCase";
CHAR *src;
CHAR *buf;
CHAR *str;
UINT32 ret;
src = LOS_MemAlloc(g_testLmsPool, strlen(string));
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
(VOID)__memset(src, 0, strlen(string));
PRINTK("%d\n", __LINE__);
str = __strcpy(src, string);
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
PRINTK("%d\n", __LINE__);
buf = LOS_MemAlloc(g_testLmsPool, 8); /* mem size 8 */
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
buf[7] = '\0'; /* end index 7 */
PRINTK("%d\n", __LINE__);
ret = strcpy_s(buf, 100, src); /* Check LMS detection information when the strcpy_s dest max set 100 overflows. */
PRINTK("%d\n", __LINE__);
ret = LOS_MemFree(g_testLmsPool, buf);
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
ret = LOS_MemFree(g_testLmsPool, src);
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
return LOS_OK;
}
/* LmsTestStrcpy_sOverflow */
VOID ItLosLms024(void)
{
TEST_ADD_CASE("ItLosLms024", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
}
......@@ -130,6 +130,10 @@ void TestKernel(void)
ItSuiteLosDynlink();
#endif
#if (LOS_KERNEL_LMS_TEST == 1)
ItSuiteLosLms();
#endif
#if (LOS_KERNEL_PM_TEST == 1)
ItSuiteLosPm();
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册