Commit 7a98cd2b authored by Pavel Emelyanov's avatar Pavel Emelyanov

files: Sanitize fd restore state machine again

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent ebc1ac8b
...@@ -442,7 +442,7 @@ static int open_special_fdinfo(int pid, struct fdinfo_entry *fe, ...@@ -442,7 +442,7 @@ static int open_special_fdinfo(int pid, struct fdinfo_entry *fe,
int prepare_fds(int pid) int prepare_fds(int pid)
{ {
u32 type = 0, err = -1, ret; u32 type = 0, ret;
int fdinfo_fd; int fdinfo_fd;
int state; int state;
off_t offset, magic_offset; off_t offset, magic_offset;
...@@ -464,34 +464,29 @@ int prepare_fds(int pid) ...@@ -464,34 +464,29 @@ int prepare_fds(int pid)
lseek(fdinfo_fd, magic_offset, SEEK_SET); lseek(fdinfo_fd, magic_offset, SEEK_SET);
while (1) { while (1) {
ret = read(fdinfo_fd, &fe, sizeof(fe)); ret = read_img_eof(fdinfo_fd, &fe);
if (ret == 0) if (ret <= 0)
break; break;
if (ret != sizeof(fe)) { if (fd_is_special(&fe))
pr_perror("%d: Bad fdinfo entry", pid); ret = open_special_fdinfo(pid, &fe,
goto err; fdinfo_fd, state);
else {
offset = lseek(fdinfo_fd, 0, SEEK_CUR);
ret = open_fdinfo(pid, &fe, &fdinfo_fd, state);
lseek(fdinfo_fd, offset + fe.len, SEEK_SET);
} }
if (fd_is_special(&fe)) { if (ret)
if (open_special_fdinfo(pid, &fe, fdinfo_fd, state)) break;
goto err;
continue;
} }
offset = lseek(fdinfo_fd, 0, SEEK_CUR); if (ret)
break;
if (open_fdinfo(pid, &fe, &fdinfo_fd, state))
goto err;
lseek(fdinfo_fd, offset + fe.len, SEEK_SET);
}
} }
err = 0;
err:
close(fdinfo_fd); close(fdinfo_fd);
return err; return ret;
} }
static struct fmap_fd *pull_fmap_fd(int pid, unsigned long start) static struct fmap_fd *pull_fmap_fd(int pid, unsigned long start)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment