diff --git a/test/extram/rom/rom.c b/test/extram/rom/rom.c index dba5047..c284bfb 100644 --- a/test/extram/rom/rom.c +++ b/test/extram/rom/rom.c @@ -73,6 +73,10 @@ void main(void) { // 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; + case TEST14: { + // pass a string beyond end of extram + println((uint32_t)UVM32_EXTRAM_BASE); // extram has been shrunk, this is now out of bounds, + } break; } } diff --git a/test/extram/shared.h b/test/extram/shared.h index ec550ea..05d77a8 100644 --- a/test/extram/shared.h +++ b/test/extram/shared.h @@ -15,5 +15,6 @@ enum { TEST11, TEST12, TEST13, + TEST14, }; diff --git a/test/extram/test/tests.c b/test/extram/test/tests.c index 0d50ec3..ebfadb5 100644 --- a/test/extram/test/tests.c +++ b/test/extram/test/tests.c @@ -369,4 +369,35 @@ void test_extram_buf_slice_beyond_extram_end(void) { TEST_ASSERT_EQUAL(evt.data.err.errcode, UVM32_ERR_MEM_RD); } +void test_extram_buf_cstr_beyond_extram_end(void) { + // run the vm + uvm32_run(&vmst, &evt, 100); + TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst)); + + // 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, TEST14); + + 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); + + // replace extram with a tiny one, so read is off the end + uint32_t r[3]; + // non-zero so string never terminates + memset(r, 0xAA, sizeof(r)); + uvm32_extram(&vmst, (uint8_t *)r, sizeof(r)); + + // 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_run(&vmst, &evt, 100); + TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_ERR); + TEST_ASSERT_EQUAL(evt.data.err.errcode, UVM32_ERR_MEM_RD); +} +