From a785d2eb12487bd48ffc2471af43d2a7f50431ff Mon Sep 17 00:00:00 2001 From: Maurizio Porrato Date: Fri, 24 Jan 2020 00:31:02 +0000 Subject: [PATCH] Fix buffer overflow loading images --- dsim.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dsim.c b/dsim.c index 86f23bb..f58bf72 100644 --- a/dsim.c +++ b/dsim.c @@ -525,12 +525,14 @@ int load_image(char *filename) int fd; ssize_t r; ssize_t pos; + uint8_t *buf; fd = open(filename, O_RDONLY); if (fd < 0) return fd; + buf = (uint8_t *)ram; for (pos=0;;) { - r = read(fd, &ram[pos], sizeof(ram)); + r = read(fd, &buf[pos], sizeof(ram)-pos); if (r > 0) pos += r; else {