diff options
| author | Alistair Popple <alistair@popple.id.au> | 2018-11-09 12:10:23 +1100 |
|---|---|---|
| committer | Alistair Popple <alistair@popple.id.au> | 2018-11-09 12:18:16 +1100 |
| commit | 5bf4a0142b58d60a9c09aea0930aa612f46053a9 (patch) | |
| tree | 0595ece2fcb4690dc187c06149d7d0c4c4887835 /libpdbg | |
| parent | 60b2ec3a95ddebd8943bdf5d61f700d7d2fca923 (diff) | |
| download | pdbg-5bf4a0142b58d60a9c09aea0930aa612f46053a9.tar.gz pdbg-5bf4a0142b58d60a9c09aea0930aa612f46053a9.zip | |
device.c: Fix pdbg_target_address
Commit 936dbdcedb27 ("libpdbg: Rework target addressing") introduced a
bug leading to the following assertion failing:
pdbg: libpdbg/device.c:634: pdbg_target_address: Assertion `(pos + n) <= p->len' failed.
When this function was reworked the index parameter was dropped as
every caller set index == 0. Removal should have also resulted in the
local pos variable being removed. Instead it was set as if index == 1
resulting in the above violation.
Fix the bug and add a test to check pdbg_target_address().
Signed-off-by: Alistair Popple <alistair@popple.id.au>
Diffstat (limited to 'libpdbg')
| -rw-r--r-- | libpdbg/device.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/libpdbg/device.c b/libpdbg/device.c index 9557172..f81b1b5 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -626,15 +626,14 @@ uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *out_size) const struct dt_property *p; u32 na = dt_n_address_cells(target); u32 ns = dt_n_size_cells(target); - u32 pos, n; + u32 n; p = dt_require_property(target, "reg", -1); n = (na + ns) * sizeof(u32); - pos = n; - assert((pos + n) <= p->len); + assert(n <= p->len); if (out_size) - *out_size = dt_get_number(p->prop + pos + na * sizeof(u32), ns); - return dt_get_number(p->prop + pos, na); + *out_size = dt_get_number(p->prop + na * sizeof(u32), ns); + return dt_get_number(p->prop, na); } void pdbg_targets_init(void *fdt) |

