From: Keith Packard Date: Fri, 27 Apr 2018 00:24:51 +0000 (-0700) Subject: altoslib: Fix data fetching during flashing of cc1111-based devices X-Git-Tag: 1.8.6~1^2~97 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=8612c1287a1c458a17f33af1d679d30a13dea772 altoslib: Fix data fetching during flashing of cc1111-based devices We want to get enough information about the target device to verify that the new firmware matches, so fetch 512 bytes instead of just barely enough to cover the romconfig data. Also catch out-of-bounds accesses and handle them, in case even this large array isn't enough. Signed-off-by: Keith Packard --- diff --git a/altoslib/AltosDebug.java b/altoslib/AltosDebug.java index 24a25933..a44eb12f 100644 --- a/altoslib/AltosDebug.java +++ b/altoslib/AltosDebug.java @@ -264,8 +264,8 @@ public class AltosDebug { public AltosRomconfig romconfig() throws InterruptedException { try { - byte[] bytes = read_memory(0xa0, 10); - AltosHexfile hexfile = new AltosHexfile (bytes, 0xa0); + byte[] bytes = read_memory(0x00, 0x200); + AltosHexfile hexfile = new AltosHexfile (bytes, 0x00); return new AltosRomconfig(hexfile); } catch (IOException ie) { } diff --git a/altoslib/AltosHexfile.java b/altoslib/AltosHexfile.java index 6aa98383..f2ab4bea 100644 --- a/altoslib/AltosHexfile.java +++ b/altoslib/AltosHexfile.java @@ -294,15 +294,19 @@ public class AltosHexfile { if (usb_descriptors == null) return -1; - /* Walk the descriptors looking for the device */ - a = usb_descriptors.address; - while (get_u8(a+1) != AO_USB_DESC_DEVICE) { - int delta = get_u8(a); - a += delta; - if (delta == 0 || a >= max_address) - return -1; + try { + /* Walk the descriptors looking for the device */ + a = usb_descriptors.address; + while (get_u8(a+1) != AO_USB_DESC_DEVICE) { + int delta = get_u8(a); + a += delta; + if (delta == 0 || a >= max_address) + return -1; + } + return a; + } catch (ArrayIndexOutOfBoundsException ae) { + return -1; } - return a; } public AltosUsbId find_usb_id() { diff --git a/altoslib/AltosRomconfig.java b/altoslib/AltosRomconfig.java index 1fbb4115..44a3fa60 100644 --- a/altoslib/AltosRomconfig.java +++ b/altoslib/AltosRomconfig.java @@ -35,12 +35,12 @@ public class AltosRomconfig { System.out.printf("no symbol %s\n", name); throw new AltosNoSymbol(name); } - if (hexfile.address <= symbol.address && symbol.address + len < hexfile.max_address) { + if (hexfile.address <= symbol.address && symbol.address + len <= hexfile.max_address) { System.out.printf("%s: %x\n", name, symbol.address); return symbol.address; } - System.out.printf("invalid symbol addr %x range is %x - %x\n", - symbol.address, hexfile.address, hexfile.max_address); + System.out.printf("invalid symbol addr %x len %d range is %x - %x\n", + symbol.address, len, hexfile.address, hexfile.max_address); throw new AltosNoSymbol(name); }