ARMmbed / ARMmbed/DAPLink

swd_read_block() / swd_write_block() misalignment

Open
#996 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
2.8k
Forks
1.1k
Avg merge
3d 12h
Merged PRs (30d)
1

Description

Hello,

the two functions swd_read_block() and swd_write_block() will stumble into misalignment, if their callers swd_read_memory() and swd_write_memory() are called with differently aligned src/dst, e.g. "address"=0x20001ef**1** (target), "data"=0x20013ee**0**.

Important part are the last digits. If the addresses have a different alignment, swd_read_block()... crashes, because the function actually expects "data" to be 32bit aligned.

Fix is easy: first read the 32bit value from the target into an aligned value and then do a memcpy() from this value to the actual destination.

If performance is an issue, the special case "misaligned" has to be handled extra.

If I should provide a PR, let me know.

Contributor guide

Open the contributing guide

Research direction

Start by tracing swd_read_memory() and swd_write_memory() into swd_read_block() and swd_write_block(), then inspect how destination and source alignment are handled. Reproduce the differently aligned address case described in the issue and verify that block reads and writes complete without misalignment crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.