Skip to content

Commit

Permalink
Fixed sdps crash for some size flash.bin
Browse files Browse the repository at this point in the history
memcpy size can't exceed input memory buffer size.
It is fix for 3f512a6

Signed-off-by: Frank Li <frank.li@nxp.com>
  • Loading branch information
nxpfrankli committed Nov 9, 2023
1 parent 596831e commit de317f5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libuuu/hidreport.cpp
Expand Up @@ -78,6 +78,10 @@ int HIDReport::write(const void *p, size_t sz, uint8_t report_id)
m_out_buff[0] = report_id;

size_t s = sz - off;
size_t copy_sz = s;

if (copy_sz > m_size_out)
copy_sz = m_size_out;

This comment has been minimized.

Copy link
@bith3ad

bith3ad Nov 9, 2023

@nxpfrankli this is done two lines below, instead now the report_id == 2 is skipped again.

This comment has been minimized.

Copy link
@nxpfrankli

nxpfrankli Nov 9, 2023

Author Contributor

This is because windows HIDAPI's problem. We can't block this function. I supposed you have not tested your system at windows.

This comment has been minimized.

Copy link
@bith3ad

bith3ad Nov 9, 2023

I see the issue now.. took me to long (it's to late). I think we just need split the if for the report_id == 2. I will prepare a patch, which fixes this without introducing a 2nd copy parameter. Sorry for the regression.


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

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

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

Expand Down

0 comments on commit de317f5

Please sign in to comment.