Skip to content

Commit de317f5

Browse files
committed
Fixed sdps crash for some size flash.bin
memcpy size can't exceed input memory buffer size. It is fix for 3f512a6 Signed-off-by: Frank Li <frank.li@nxp.com>
1 parent 596831e commit de317f5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libuuu/hidreport.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ int HIDReport::write(const void *p, size_t sz, uint8_t report_id)
7878
m_out_buff[0] = report_id;
7979

8080
size_t s = sz - off;
81+
size_t copy_sz = s;
82+
83+
if (copy_sz > m_size_out)
84+
copy_sz = m_size_out;
8185

8286
/*
8387
* The Windows HIDAPI is ver strict. It always require to send
@@ -88,7 +92,8 @@ int HIDReport::write(const void *p, size_t sz, uint8_t report_id)
8892
if (s > m_size_out || report_id == 2)
8993
s = m_size_out;
9094

91-
memcpy(m_out_buff.data() + m_size_payload, buff + off, s);
95+
/* copy_sz can't be bigger then input data size, otherwise access unpaged memory */
96+
memcpy(m_out_buff.data() + m_size_payload, buff + off, copy_sz);
9297

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

0 commit comments

Comments
 (0)