ihex: Fix a buffer-overread spotted by AddressSanitizer

This commit is contained in:
Richard Hughes 2021-02-08 18:10:38 +00:00
parent abdc82b1c1
commit 6920eb1214

View File

@ -90,11 +90,6 @@ fu_ihex_firmware_record_new (guint ln, const gchar *line,
rcd->ln = ln;
rcd->data = g_byte_array_new ();
rcd->buf = g_string_new (line);
rcd->byte_cnt = fu_firmware_strparse_uint8 (line + 1);
rcd->addr = fu_firmware_strparse_uint16 (line + 3);
rcd->record_type = fu_firmware_strparse_uint8 (line + 7);
/* check there's enough data for the smallest possible record */
if (rcd->buf->len < 11) {
g_set_error (error,
FWUPD_ERROR,
@ -103,6 +98,9 @@ fu_ihex_firmware_record_new (guint ln, const gchar *line,
(guint) rcd->buf->len);
return NULL;
}
rcd->byte_cnt = fu_firmware_strparse_uint8 (line + 1);
rcd->addr = fu_firmware_strparse_uint16 (line + 3);
rcd->record_type = fu_firmware_strparse_uint8 (line + 7);
/* position of checksum */
line_end = 9 + rcd->byte_cnt * 2;