ihex: Do not dump binary out to the terminal for corrupt files

This commit is contained in:
Richard Hughes 2020-12-10 09:41:26 +00:00
parent 6271176c33
commit f3539621ee

View File

@ -69,11 +69,24 @@ fu_ihex_firmware_record_new (guint ln, const gchar *line,
/* check starting token */ /* check starting token */
if (line[0] != ':') { if (line[0] != ':') {
g_set_error (error, g_autoptr(GString) str = g_string_new (NULL);
FWUPD_ERROR, for (gsize i = 0; line[i] != '\0' && i < 5; i++) {
FWUPD_ERROR_INVALID_FILE, if (!g_ascii_isprint (line[i]))
"invalid starting token: %s", break;
line); g_string_append_c (str, line[i]);
}
if (str->len > 0) {
g_set_error (error,
FWUPD_ERROR,
FWUPD_ERROR_INVALID_FILE,
"invalid starting token: %s",
str->str);
return NULL;
}
g_set_error_literal (error,
FWUPD_ERROR,
FWUPD_ERROR_INVALID_FILE,
"invalid starting token");
return NULL; return NULL;
} }