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;
|
int fd;
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
ssize_t pos;
|
ssize_t pos;
|
||||||
|
uint8_t *buf;
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
buf = (uint8_t *)ram;
|
||||||
for (pos=0;;) {
|
for (pos=0;;) {
|
||||||
r = read(fd, &ram[pos], sizeof(ram));
|
r = read(fd, &buf[pos], sizeof(ram)-pos);
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
pos += r;
|
pos += r;
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue