[bugfix] Restore overflowed memory copy#661
[bugfix] Restore overflowed memory copy#661stevstrong merged 2 commits intorogerclarkmelbourne:masterfrom
Conversation
|
I think the issue is line 68-69: The 4 bytes pointed by the pbUsrBuf will be overwritten, pdwVal is a 32 bit pointer. I think the best solution would be to add a dummy byte to the usb_cdcacm_line_coding struct (between lines 154-155) so that the memory allocation will always reserve 8 bytes, this way the speed advantage is kept. |
|
Hm, having a closer look at the function PMAToUserBufferCopy, it seems to me that it will copy twice as much data as needed. Result: n x 4 bytes will be copied. Or do I miss something? |
|
I was missing that the packet buffer memory, as well as all USB registers, are aligned to 32-bit word boundaries although they are 16-bit wide only, see RM0008, chapter 23.5. Can you please check if this solves the issue? |
yeah, dummy reserved byte can solve my problem, But in fact, the parameters
can only be even number, cann't be odd number |
It looks okay. |
|
Yea, it looks okay, but it is not fast. The difference to the original is that the number of times to copy data in word (16-bit) format will not be rounded up. |
|
I merged my variant as it seems to be a more effective solution than yours. |
Arduino_STM32/STM32F1/system/libmaple/include/libmaple/usb_cdcacm.h
Line 155 in a3a5686
This structure takes up 7 bytes of RAM, under some memory-aligned compilation rules, it takes up 8bytes
This structural variable is passed into the
PMAToUserBufferCopyfunction as au8 * pbUsrBufparameter in hereArduino_STM32/STM32F1/cores/maple/libmaple/usb/usb_lib/usb_mem.c
Line 60 in a3a5686
If the length of the
pbUsrBufparameter is odd, it will tamper with the last byte of the address.If the compiler is single-byte aligned, the structure
line_codingtakes up 7bytes, At this point, the value of the variable that followsline_codingwill be tampered byPMAToUserBufferCopy.for example:
The normal value of the
testvariable is 0. When thefunction has been executed
The value of the
testvariable will be tampered, not equal 0.thie PR restored tampered data.