realtek: Fail on shorter data read that may lead to an underflow

Reported by: Keith Linneman (LinnemanLabs)
This commit is contained in:
Marco Trevisan (Treviño)
2026-07-13 08:13:46 +00:00
committed by Marco Trevisan
parent 2e2ba8b227
commit 07152e43ef
+8
View File
@@ -638,6 +638,14 @@ fp_cmd_receive_cb (FpiUsbTransfer *transfer,
{ {
g_autofree guchar *read_buf = NULL; g_autofree guchar *read_buf = NULL;
if ((gsize) transfer->actual_length < self->trans_data_len)
{
fpi_ssm_mark_failed (transfer->ssm,
fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
"Truncated data received"));
return;
}
read_buf = g_malloc0 (sizeof (guchar) * (self->trans_data_len)); read_buf = g_malloc0 (sizeof (guchar) * (self->trans_data_len));
memcpy (read_buf, transfer->buffer, self->trans_data_len); memcpy (read_buf, transfer->buffer, self->trans_data_len);
self->read_data = g_steal_pointer (&read_buf); self->read_data = g_steal_pointer (&read_buf);