diff --git a/libr/asm/p/asm_cris_gnu.c b/libr/asm/p/asm_cris_gnu.c index dfa304f515..8a64a8ae42 100644 --- a/libr/asm/p/asm_cris_gnu.c +++ b/libr/asm/p/asm_cris_gnu.c @@ -26,7 +26,14 @@ static RStrBuf *buf_global = NULL; static unsigned char bytes[8]; static int cris_buffer_read_memory (bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) { - memcpy (myaddr, bytes, length); + int delta = (memaddr - Offset); + if (delta < 0) { + return -1; // disable backward reads + } + if ((delta + length) > 8) { + return -1; + } + memcpy (myaddr, bytes + delta, length); return 0; } diff --git a/libr/asm/p/asm_hppa_gnu.c b/libr/asm/p/asm_hppa_gnu.c index bda704a2f7..086020e795 100644 --- a/libr/asm/p/asm_hppa_gnu.c +++ b/libr/asm/p/asm_hppa_gnu.c @@ -27,7 +27,14 @@ static int hppa_buffer_read_memory (bfd_vma memaddr, bfd_byte *myaddr, ut32 leng return 0; } #endif - memcpy (myaddr, bytes, length); + int delta = (memaddr - Offset); + if (delta < 0) { + return -1; // disable backward reads + } + if ((delta + length) > 4) { + return -1; + } + memcpy (myaddr, bytes + delta, length); return 0; } diff --git a/libr/asm/p/asm_lanai_gnu.c b/libr/asm/p/asm_lanai_gnu.c index 3da59579fb..f5474ab483 100644 --- a/libr/asm/p/asm_lanai_gnu.c +++ b/libr/asm/p/asm_lanai_gnu.c @@ -14,7 +14,14 @@ static RStrBuf *buf_global = NULL; static unsigned char bytes[4]; static int lanai_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) { - memcpy (myaddr, bytes, length); + int delta = (memaddr - Offset); + if (delta < 0) { + return -1; // disable backward reads + } + if ((delta + length) > 4) { + return -1; + } + memcpy (myaddr, bytes + delta, length); return 0; } diff --git a/libr/asm/p/asm_mips_gnu.c b/libr/asm/p/asm_mips_gnu.c index 3aeeaf8484..c83cb44053 100644 --- a/libr/asm/p/asm_mips_gnu.c +++ b/libr/asm/p/asm_mips_gnu.c @@ -21,7 +21,14 @@ static char *pre_cpu = NULL; static char *pre_features = NULL; static int mips_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info) { - memcpy (myaddr, bytes, length); + int delta = (memaddr - Offset); + if (delta < 0) { + return -1; // disable backward reads + } + if ((delta + length) > 4) { + return -1; + } + memcpy (myaddr, bytes + delta, length); return 0; } diff --git a/libr/asm/p/asm_ppc_gnu.c b/libr/asm/p/asm_ppc_gnu.c index 977b22fc20..f3724d7402 100644 --- a/libr/asm/p/asm_ppc_gnu.c +++ b/libr/asm/p/asm_ppc_gnu.c @@ -17,7 +17,14 @@ static RStrBuf *buf_global = NULL; static unsigned char bytes[4]; static int ppc_buffer_read_memory (bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) { - memcpy (myaddr, bytes, length); + int delta = (memaddr - Offset); + if (delta < 0) { + return -1; // disable backward reads + } + if ((delta + length) > 4) { + return -1; + } + memcpy (myaddr, bytes + delta, length); return 0; } diff --git a/libr/asm/p/asm_sparc_gnu.c b/libr/asm/p/asm_sparc_gnu.c index 1f1b815fe2..4539dd49a4 100644 --- a/libr/asm/p/asm_sparc_gnu.c +++ b/libr/asm/p/asm_sparc_gnu.c @@ -15,6 +15,13 @@ static RStrBuf *buf_global = NULL; static unsigned char bytes[4]; static int sparc_buffer_read_memory (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info) { + int delta = (memaddr - Offset); + if (delta < 0) { + return -1; // disable backward reads + } + if ((delta + length) > 4) { + return -1; + } memcpy (myaddr, bytes, length); return 0; } diff --git a/libr/asm/p/asm_v850_gnu.c b/libr/asm/p/asm_v850_gnu.c index c2f69b0254..fce594640d 100644 --- a/libr/asm/p/asm_v850_gnu.c +++ b/libr/asm/p/asm_v850_gnu.c @@ -16,7 +16,14 @@ static RStrBuf *buf_global = NULL; static ut8 bytes[8]; static int v850_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) { - memcpy (myaddr, bytes, length); + int delta = (memaddr - Offset); + if (delta < 0) { + return -1; // disable backward reads + } + if ((delta + length) > 8) { + return -1; + } + memcpy (myaddr, bytes + delta, length); return 0; } diff --git a/test/db/anal/v850.gnu b/test/db/anal/v850.gnu new file mode 100644 index 0000000000..ebca0e9572 --- /dev/null +++ b/test/db/anal/v850.gnu @@ -0,0 +1,12 @@ +NAME=v850.gnu proper imm32 handling +FILE=malloc://1024 +CMDS=<