Skip to content

Commit 797fd04

Browse files
W-M-Rxiaoxiang781216
authored andcommitted
kasantest: Fix errors running on 64 bit
1. Change 'heap' to a global variable. When using the software tag 'kasan', the base of 'heap' is dynamically changing, which may result in runtime errors 2. Modify the length of the argv array to ensure that all 64 bit addresses can be copied 3. After initialization, the registration of the heap must be canceled Signed-off-by: wangmingrong1 <[email protected]>
1 parent 85ad50c commit 797fd04

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

testing/kasantest/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ PRIORITY = SCHED_PRIORITY_DEFAULT
2828
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
2929

3030
CFLAGS += -Wno-error -Wno-use-after-free
31+
CFLAGS += -Wno-array-bounds -Wno-free-nonheap-object
3132

3233
include $(APPDIR)/Application.mk

testing/kasantest/kasantest.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef struct testcase_s
5050

5151
typedef struct run_s
5252
{
53-
char argv[16];
53+
char argv[32];
5454
FAR const testcase_t *testcase;
5555
FAR struct mm_heap_s *heap;
5656
size_t size;
@@ -90,6 +90,8 @@ const static testcase_t g_kasan_test[] =
9090
{test_heap_memmove, "heap memmove"}
9191
};
9292

93+
static char g_kasan_heap[65536] aligned_data(8);
94+
9395
/****************************************************************************
9496
* Private Functions
9597
****************************************************************************/
@@ -213,7 +215,7 @@ static int run_test(FAR const testcase_t *test)
213215
* it can be released correctly.
214216
*/
215217

216-
run = malloc(sizeof(run_t) + heap_size);
218+
run = (run_t *)g_kasan_heap;
217219
if (!run)
218220
{
219221
return ERROR;
@@ -222,7 +224,7 @@ static int run_test(FAR const testcase_t *test)
222224
snprintf(run->argv, sizeof(run->argv), "%p", run);
223225
run->testcase = test;
224226
run->size = rand() % (heap_size / 2) + 1;
225-
run->heap = mm_initialize("kasan", &run[1], heap_size);
227+
run->heap = mm_initialize("kasan", (struct mm_heap_s *)&run[1], heap_size);
226228
if (!run->heap)
227229
{
228230
free(run);
@@ -237,13 +239,14 @@ static int run_test(FAR const testcase_t *test)
237239
waitpid(pid, &status, 0);
238240
if (status == 0)
239241
{
240-
printf("KASan test: %s, size: %d FAIL\n", test->name, run->size);
242+
printf("KASan test: %s, size: %ld FAIL\n", test->name, run->size);
241243
}
242244
else
243245
{
244-
printf("KASan test: %s, size: %d PASS\n", test->name, run->size);
246+
printf("KASan test: %s, size: %ld PASS\n", test->name, run->size);
245247
}
246248

249+
mm_uninitialize(run->heap);
247250
return 0;
248251
}
249252

0 commit comments

Comments
 (0)