Fix buffer overflow loading images

This commit is contained in:
Maurizio Porrato 2020-01-24 00:31:02 +00:00
parent f8ec7c2bee
commit a785d2eb12
1 changed files with 3 additions and 1 deletions

4
dsim.c
View File

@ -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 {