Check for overflow when copying buffers with huge offset values

This commit is contained in:
Richard Hughes 2022-07-13 21:00:52 +01:00
parent 56e5c1b7a9
commit 1ffc2608b0

View File

@ -342,7 +342,7 @@ fu_memcpy_safe(guint8 *dst,
(guint)src_sz); (guint)src_sz);
return FALSE; return FALSE;
} }
if (n + src_offset > src_sz) { if (src_offset > src_sz || n + src_offset > src_sz) {
g_set_error(error, g_set_error(error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_READ, FWUPD_ERROR_READ,
@ -361,7 +361,7 @@ fu_memcpy_safe(guint8 *dst,
(guint)dst_sz); (guint)dst_sz);
return FALSE; return FALSE;
} }
if (n + dst_offset > dst_sz) { if (dst_offset > dst_sz || n + dst_offset > dst_sz) {
g_set_error(error, g_set_error(error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_WRITE, FWUPD_ERROR_WRITE,