aboutsummaryrefslogtreecommitdiff
path: root/extmod/machine_mem.c
diff options
context:
space:
mode:
authorArrowana <pierre.duval@gadz.org>2020-10-31 13:34:58 +1100
committerDamien George <damien@micropython.org>2020-11-13 11:13:37 +1100
commit922f81dfd1b94e23f23f05aac0ecafac8645ce46 (patch)
tree939e2c83ba702b812d455ec8d9e315c8c2b0cefa /extmod/machine_mem.c
parent8a917ad2529ea3df5f47e2be5b4edf362d2d03f6 (diff)
extmod/machine_mem: Only allow integers in machine.memX subscript.
Prior to this change machine.mem32['foo'] (or using any other non-integer subscript) could result in a fault due to 'foo' being interpreted as an integer. And when writing code it's hard to tell if the fault is due to a bad subscript type, or an integer subscript that specifies an invalid memory address. The type of the object used in the subscript is now tested to be an integer by using mp_obj_get_int_truncated instead of mp_obj_int_get_truncated. The performance hit of this change is minimal, and machine.memX objects are more for convenience than performance (there are many other ways to read/write memory in a faster way), Fixes issue #6588.
Diffstat (limited to 'extmod/machine_mem.c')
-rw-r--r--extmod/machine_mem.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/extmod/machine_mem.c b/extmod/machine_mem.c
index a1494bd51..73e2f7fd1 100644
--- a/extmod/machine_mem.c
+++ b/extmod/machine_mem.c
@@ -40,7 +40,7 @@
#if !defined(MICROPY_MACHINE_MEM_GET_READ_ADDR) || !defined(MICROPY_MACHINE_MEM_GET_WRITE_ADDR)
STATIC uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) {
- uintptr_t addr = mp_obj_int_get_truncated(addr_o);
+ uintptr_t addr = mp_obj_get_int_truncated(addr_o);
if ((addr & (align - 1)) != 0) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("address %08x is not aligned to %d bytes"), addr, align);
}