diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-23 00:28:39 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-23 00:28:39 +0100 |
commit | 19eb401498488db1e5c39fc199e59bf96df2828d (patch) | |
tree | e1ebec6b751961a8c9a01bdcaf7fd8cb536e83de | |
parent | ae9bc91713f86cfc16e801ca33654a47082ddb2b (diff) | |
download | ovm-19eb401498488db1e5c39fc199e59bf96df2828d.tar.gz ovm-19eb401498488db1e5c39fc199e59bf96df2828d.tar.bz2 ovm-19eb401498488db1e5c39fc199e59bf96df2828d.zip |
Fixed bugs with ordering of bytes in some operations
Also fixed an overflow error in vm_dup_word, where I underflow the
index of vm->stack.data which causes a buffer overflow.
-rw-r--r-- | src/runtime.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/runtime.c b/src/runtime.c index f653ac3..32350e1 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -504,7 +504,8 @@ err_t vm_dup_word(vm_t *vm, word w) return ERR_STACK_UNDERFLOW; byte bytes[WORD_SIZE] = {0}; for (size_t i = 0; i < WORD_SIZE; ++i) - bytes[i] = vm->stack.data[vm->stack.ptr - 1 - (WORD_SIZE * (w + 1)) + i]; + bytes[WORD_SIZE - i - 1] = + vm->stack.data[vm->stack.ptr - (WORD_SIZE * (w + 1)) + i]; return vm_push_word(vm, DWORD(convert_bytes_to_word(bytes))); } @@ -525,7 +526,7 @@ err_t vm_pop_hword(vm_t *vm, data_t *ret) { data_t b = {0}; vm_pop_byte(vm, &b); - bytes[HWORD_SIZE - 1 - i] = b.as_byte; + bytes[i] = b.as_byte; } *ret = DWORD(convert_bytes_to_hword(bytes)); return ERR_OK; @@ -540,7 +541,7 @@ err_t vm_pop_word(vm_t *vm, data_t *ret) { data_t b = {0}; vm_pop_byte(vm, &b); - bytes[WORD_SIZE - 1 - i] = b.as_byte; + bytes[i] = b.as_byte; } *ret = DWORD(convert_bytes_to_word(bytes)); return ERR_OK; |