Add a missing bounds check, fix an off-by-one bounds check and replace
asserts with error messages.
https://sourceware.org/bugzilla/show_bug.cgi?id=25068
Signed-off-by: Mark Wielaard <mark@klomp.org>
+2019-10-17 Mark Wielaard <mark@klomp.org>
+
+ * i386_data.h (FCT_sel): Check for param_start + 2 >= end instead
+ of just >.
+ * i386_disasm.c (i386_disasm): Check param_start < end. Don't
+ assert, but assign INVALID to str. Make sure we get past any
+ unrecognized opcode.
+
2019-09-07 Mark Wielaard <mark@klomp.org>
* riscv_disasm.c (riscv_disasm): Use UINT64_C to make calculation
{
assert (d->opoff1 % 8 == 0);
assert (d->opoff1 / 8 == 5);
- if (*d->param_start + 2 > d->end)
+ if (*d->param_start + 2 >= d->end)
return -1;
*d->param_start += 2;
uint16_t absval = read_2ubyte_unaligned (&d->data[5]);
/* Account for displacement. */
if ((modrm & 0xc7) == 5 || (modrm & 0xc0) == 0x80
- || ((modrm & 0xc7) == 0x4 && (codep[0] & 0x7) == 0x5))
+ || ((modrm & 0xc7) == 0x4
+ && param_start < end
+ && (codep[0] & 0x7) == 0x5))
param_start += 4;
else if ((modrm & 0xc0) == 0x40)
param_start += 1;
}
FALLTHROUGH;
default:
- assert (! "INVALID not handled");
+ str = "INVALID not handled";
+ break;
}
}
else
/* Invalid (or at least unhandled) opcode. */
if (prefixes != 0)
goto print_prefix;
- assert (*startp == data);
- ++data;
+ /* Make sure we get past the unrecognized opcode if we haven't yet. */
+ if (*startp == data)
+ ++data;
ADD_STRING ("(bad)");
addr += data - begin;