mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-02 15:25:21 +00:00
bfd: Don't leak image-open flags into bfdopen
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
16
bfd.c
16
bfd.c
@@ -87,17 +87,27 @@ static void buf_put(struct xbuf *xb)
|
|||||||
xb->data = NULL;
|
xb->data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bfdopen(struct bfd *f, int mode)
|
static int bfdopen(struct bfd *f, bool writable)
|
||||||
{
|
{
|
||||||
if (buf_get(&f->b)) {
|
if (buf_get(&f->b)) {
|
||||||
close(f->fd);
|
close(f->fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
f->mode = mode;
|
f->writable = writable;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bfdopenr(struct bfd *f)
|
||||||
|
{
|
||||||
|
return bfdopen(f, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bfdopenw(struct bfd *f)
|
||||||
|
{
|
||||||
|
return bfdopen(f, true);
|
||||||
|
}
|
||||||
|
|
||||||
static int bflush(struct bfd *bfd);
|
static int bflush(struct bfd *bfd);
|
||||||
static bool flush_failed = false;
|
static bool flush_failed = false;
|
||||||
|
|
||||||
@@ -109,7 +119,7 @@ int bfd_flush_images(void)
|
|||||||
void bclose(struct bfd *f)
|
void bclose(struct bfd *f)
|
||||||
{
|
{
|
||||||
if (bfd_buffered(f)) {
|
if (bfd_buffered(f)) {
|
||||||
if ((f->mode != O_RDONLY) && bflush(f) < 0) {
|
if (f->writable && bflush(f) < 0) {
|
||||||
/*
|
/*
|
||||||
* This is to propagate error up. It's
|
* This is to propagate error up. It's
|
||||||
* hardly possible by returning and
|
* hardly possible by returning and
|
||||||
|
11
image.c
11
image.c
@@ -239,8 +239,15 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...)
|
|||||||
img->_x.fd = ret;
|
img->_x.fd = ret;
|
||||||
if (oflags & O_NOBUF)
|
if (oflags & O_NOBUF)
|
||||||
bfd_setraw(&img->_x);
|
bfd_setraw(&img->_x);
|
||||||
else if (bfdopen(&img->_x, flags))
|
else {
|
||||||
goto err_close;
|
if (flags == O_RDONLY)
|
||||||
|
ret = bfdopenr(&img->_x);
|
||||||
|
else
|
||||||
|
ret = bfdopenw(&img->_x);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
goto err_close;
|
||||||
|
}
|
||||||
|
|
||||||
if (imgset_template[type].magic == RAW_IMAGE_MAGIC)
|
if (imgset_template[type].magic == RAW_IMAGE_MAGIC)
|
||||||
goto skip_magic;
|
goto skip_magic;
|
||||||
|
@@ -13,7 +13,7 @@ struct xbuf {
|
|||||||
|
|
||||||
struct bfd {
|
struct bfd {
|
||||||
int fd;
|
int fd;
|
||||||
int mode;
|
bool writable;
|
||||||
struct xbuf b;
|
struct xbuf b;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,7 +27,8 @@ static inline void bfd_setraw(struct bfd *b)
|
|||||||
b->b.mem = NULL;
|
b->b.mem = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bfdopen(struct bfd *f, int mode);
|
int bfdopenr(struct bfd *f);
|
||||||
|
int bfdopenw(struct bfd *f);
|
||||||
void bclose(struct bfd *f);
|
void bclose(struct bfd *f);
|
||||||
char *breadline(struct bfd *f);
|
char *breadline(struct bfd *f);
|
||||||
int bwrite(struct bfd *f, const void *buf, int sz);
|
int bwrite(struct bfd *f, const void *buf, int sz);
|
||||||
|
@@ -358,7 +358,7 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list)
|
|||||||
if (f.fd < 0)
|
if (f.fd < 0)
|
||||||
goto err_n;
|
goto err_n;
|
||||||
|
|
||||||
if (bfdopen(&f, O_RDONLY))
|
if (bfdopenr(&f))
|
||||||
goto err_n;
|
goto err_n;
|
||||||
|
|
||||||
map_files_dir = opendir_proc(pid, "map_files");
|
map_files_dir = opendir_proc(pid, "map_files");
|
||||||
@@ -733,7 +733,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bfdopen(&f, O_RDONLY))
|
if (bfdopenr(&f))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while (done < 8 && (str = breadline(&f))) {
|
while (done < 8 && (str = breadline(&f))) {
|
||||||
@@ -1165,7 +1165,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bfdopen(&f, O_RDONLY))
|
if (bfdopenr(&f))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -1616,7 +1616,7 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bfdopen(&f, O_RDONLY))
|
if (bfdopenr(&f))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
Reference in New Issue
Block a user