summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2021-06-19 07:42:17 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-06-21 09:57:57 +0200
commit191b3d820d4d1b127ae375d7b91995cad5e1ead9 (patch)
tree272160bc970dbf3727a9597c198ea0f9ecbf4065 /commands
parent589f4236c53e299f735aecee472e01a49e26f0d1 (diff)
downloadbarebox-191b3d820d4d1b127ae375d7b91995cad5e1ead9.tar.gz
barebox-191b3d820d4d1b127ae375d7b91995cad5e1ead9.tar.xz
commands: md: don't leak heap memory with unaligned accesses
Doing unaligned near file end returns bogus results: barebox@Sandbox:/ md -s /dev/stickypage 4095 00000fff: 959ff8ff . That 0x959ff8 is heap memory next to the buffer md had allocated. Fix this by adding some zeroed padding after the buffer, so it instead reads: 00000fff: 000000ff . This is arguably better user experience. This only applies to non-mappable fd's. For e.g. /dev/mem, unaligned accesses will still be passed as-is. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Link: https://lore.barebox.org/20210619054217.499815-1-ahmad@a3f.at Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/md.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/commands/md.c b/commands/md.c
index ef6a1e1bc0..d80c7cca0c 100644
--- a/commands/md.c
+++ b/commands/md.c
@@ -59,7 +59,7 @@ static int do_mem_md(int argc, char *argv[])
goto out;
}
- buf = xmalloc(RW_BUF_SIZE);
+ buf = xzalloc(RW_BUF_SIZE + 7);
do {
now = min(size, (loff_t)RW_BUF_SIZE);