summaryrefslogtreecommitdiff
path: root/altoslib/AltosHexfile.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2018-04-26 17:24:51 -0700
committerKeith Packard <keithp@keithp.com>2018-04-26 19:24:21 -0700
commit8612c1287a1c458a17f33af1d679d30a13dea772 (patch)
tree2780f7f6267ae6241517e835f61c578205e44de7 /altoslib/AltosHexfile.java
parenteee9f6128da146b0e9c711d49b2a3eb49a95aaf3 (diff)
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 <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosHexfile.java')
-rw-r--r--altoslib/AltosHexfile.java20
1 files changed, 12 insertions, 8 deletions
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() {