Fix buffer overflow loading images
This commit is contained in:
parent
f8ec7c2bee
commit
a785d2eb12
4
dsim.c
4
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 {
|
||||
|
|
Loading…
Reference in New Issue