Skip to content

Commit a1ea0c9

Browse files
committed
cmsisDAP: Avoid memcpy() on possibly overlapping buffer
I observed strange cmsisDAP behavior when building openFPGALoader with Clang/musl in release mode: CmsisDAP:display_info() shows the correct hardware capability that supports JTAG, ... firmware version : 0254 hardware capabilities : 13 SWO trace buffer size : NA ... but the detection of JTAG fails in the constructor with a strange response sequence, Hardware cap 00 01 00 JTAG init failed with: JTAG is not supported by the probe With some digging, it's found that the CmsisDAP::xfer() method without an instruction parameter may be called by the constructor with a rx_buff pointer overlapping with _ll_buffer, for which memmove() instead of memcpy() should be used. The behavior of memcpy() is undefined when dst and src overlap. Fixes: 53c5d35 ("add cmsis dap (hid) support") Signed-off-by: Yao Zi <[email protected]>
1 parent e3e93a3 commit a1ea0c9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/cmsisDAP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ int CmsisDAP::xfer(int tx_len, uint8_t *rx_buff, int rx_len)
561561
return ret;
562562
}
563563
if (rx_len)
564-
memcpy(rx_buff, _ll_buffer, rx_len);
564+
memmove(rx_buff, _ll_buffer, rx_len);
565565

566566

567567
return ret;

0 commit comments

Comments
 (0)