Skip to content

Commit

Permalink
libuuu: hidreport: fix read out-of-bound access during write
Browse files Browse the repository at this point in the history
Since commit 3f512a6 ("libuuu: hidreport: fix write size for
Windows") it may happen that the memcpy() does read outside the provided
memory. Fix this by moving the Windows HIDAPI workaround behind the
memcpy(), here no overflows can happen since the m_out_buff size is at
least m_size_out.

Signed-off-by: Marco Felsch <[email protected]>
  • Loading branch information
Marco Felsch authored and nxpfrankli committed Nov 16, 2023
1 parent 26d4b25 commit f9080cc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libuuu/hidreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,20 @@ int HIDReport::write(const void *p, size_t sz, uint8_t report_id)

size_t s = sz - off;

if (s > m_size_out)
s = m_size_out;

memcpy(m_out_buff.data() + m_size_payload, buff + off, s);

/*
* The Windows HIDAPI is ver strict. It always require to send
* buffers of the size reported by the HID Report Descriptor.
* Therefore we must to send m_size_out buffers for HID ID 2
* albeit it may not required for the last buffer.
*/
if (s > m_size_out || report_id == 2)
if (report_id == 2)
s = m_size_out;

memcpy(m_out_buff.data() + m_size_payload, buff + off, s);

int ret = m_pdev->write(m_out_buff.data(), s + m_size_payload);

if (ret < 0)
Expand Down

0 comments on commit f9080cc

Please sign in to comment.