From b083008d7b84dc5e46e1978c71ec4733f3aaa2ee Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Sat, 13 Dec 2025 23:10:49 +0000 Subject: [PATCH] Add test for reading slice in extram which is out of bounds --- test/extram/rom/rom.c | 6 +++++- test/extram/shared.h | 1 + test/extram/test/tests.c | 14 +++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/test/extram/rom/rom.c b/test/extram/rom/rom.c index f94b0a7..dba5047 100644 --- a/test/extram/rom/rom.c +++ b/test/extram/rom/rom.c @@ -49,7 +49,7 @@ void main(void) { p[2] = 'l'; p[3] = 'l'; p[4] = 'o'; - printbuf(p, 5); // try to print from extram (unterminated) + printbuf(p, 5); // try to print from extram (slice) } break; case TEST10: { uint8_t *p = (uint8_t *)UVM32_EXTRAM_BASE; @@ -69,6 +69,10 @@ void main(void) { // pass a string beyond end of MMIO region println((uint32_t)UVM32_EXTRAM_BASE + 8); // extram has been shrunk, this is now out of bounds, or no terminator found } break; + case TEST13: { + // pass a slice beyond end of extram + printbuf((uint32_t)UVM32_EXTRAM_BASE + 32, 64); // extram has been shrunk, this is now out of bounds, + } break; } } diff --git a/test/extram/shared.h b/test/extram/shared.h index a84d94f..ec550ea 100644 --- a/test/extram/shared.h +++ b/test/extram/shared.h @@ -14,5 +14,6 @@ enum { TEST10, TEST11, TEST12, + TEST13, }; diff --git a/test/extram/test/tests.c b/test/extram/test/tests.c index 09397f1..e7a3179 100644 --- a/test/extram/test/tests.c +++ b/test/extram/test/tests.c @@ -189,7 +189,7 @@ void test_extram_short_read(void) { TEST_ASSERT_EQUAL(0xCDEF, uvm32_arg_getval(&vmst, &evt, ARG0)); } -void test_extram_buf_unterminated(void) { +void test_extram_buf_slice(void) { // run the vm uvm32_run(&vmst, &evt, 100); TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst)); @@ -256,7 +256,7 @@ void test_extram_buf_terminated_rugpull(void) { TEST_ASSERT_EQUAL(evt.data.err.errcode, UVM32_ERR_MEM_RD); } -void test_extram_buf_unterminated_rugpull(void) { +void test_extram_buf_slice_rugpull(void) { // run the vm uvm32_run(&vmst, &evt, 100); TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst)); @@ -337,7 +337,7 @@ void test_extram_buf_terminated_beyond_extram_end_oobstart(void) { TEST_ASSERT_EQUAL(evt.data.err.errcode, UVM32_ERR_MEM_RD); } -void test_extram_buf_terminated_beyond_extram_end(void) { +void test_extram_buf_slice_beyond_extram_end(void) { // run the vm uvm32_run(&vmst, &evt, 100); TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst)); @@ -345,13 +345,13 @@ void test_extram_buf_terminated_beyond_extram_end(void) { // check for picktest syscall TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL); TEST_ASSERT_EQUAL(evt.data.syscall.code, SYSCALL_PICKTEST); - uvm32_arg_setval(&vmst, &evt, RET, TEST12); + uvm32_arg_setval(&vmst, &evt, RET, TEST13); uvm32_run(&vmst, &evt, 100); TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst)); // check for printbuf of val TEST_ASSERT_EQUAL(UVM32_EVT_SYSCALL, evt.typ); - TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINTLN); + TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINTBUF); // replace extram with a tiny one, so read is off the end uint32_t r[3]; @@ -362,8 +362,8 @@ void test_extram_buf_terminated_beyond_extram_end(void) { // string starts in valid extram, but no terminator will be found before hitting end of extram // check that reading from non-existent extram gives empty string and puts into err state - const char *str = uvm32_arg_getcstr(&vmst, &evt, ARG0); - TEST_ASSERT_EQUAL(0, strlen(str)); + uvm32_slice_t buf = uvm32_arg_getbuf(&vmst, &evt, ARG0, ARG1); + TEST_ASSERT_EQUAL(0, buf.len); uvm32_run(&vmst, &evt, 100); TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_ERR); TEST_ASSERT_EQUAL(evt.data.err.errcode, UVM32_ERR_MEM_RD);