2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-02 15:25:21 +00:00

Fixed NULL_RETURNS issues introduced by remote images code.

Signed-off-by: rodrigo-bruno <rbruno@gsd.inesc-id.pt>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Rodrigo Bruno
2017-03-18 17:51:37 +00:00
committed by Andrei Vagin
parent baa1dfec4d
commit 610c6d4ddd
2 changed files with 19 additions and 6 deletions

View File

@@ -327,14 +327,20 @@ static int img_write_magic(struct cr_img *img, int oflags, int type)
int do_open_remote_image(int dfd, char *path, int flags) int do_open_remote_image(int dfd, char *path, int flags)
{ {
char *snapshot_id = NULL; char *snapshot_id = NULL;
int ret; int ret, save;
/* When using namespaces, the current dir is changed so we need to /* When using namespaces, the current dir is changed so we need to
* change to previous working dir and back to correctly open the image * change to previous working dir and back to correctly open the image
* proxy and cache sockets. */ * proxy and cache sockets. */
int save = dirfd(opendir(".")); save = open(".", O_RDONLY);
if (save < 0) {
pr_perror("unable to open current working directory");
return -1;
}
if (fchdir(get_service_fd(IMG_FD_OFF)) < 0) { if (fchdir(get_service_fd(IMG_FD_OFF)) < 0) {
pr_debug("fchdir to dfd failed!\n"); pr_perror("fchdir to dfd failed!\n");
close(save);
return -1; return -1;
} }
@@ -353,7 +359,8 @@ int do_open_remote_image(int dfd, char *path, int flags)
} }
if (fchdir(save) < 0) { if (fchdir(save) < 0) {
pr_debug("fchdir to save failed!\n"); pr_perror("fchdir to save failed");
close(save);
return -1; return -1;
} }
close(save); close(save);

View File

@@ -564,9 +564,15 @@ int copy_file(int fd_in, int fd_out, size_t bytes)
{ {
ssize_t written = 0; ssize_t written = 0;
size_t chunk = bytes ? bytes : 4096; size_t chunk = bytes ? bytes : 4096;
char *buffer = (char*) malloc(chunk); char *buffer;
ssize_t ret; ssize_t ret;
buffer = xmalloc(chunk);
if (buffer == NULL) {
pr_perror("failed to allocate buffer to copy file");
return -1;
}
while (1) { while (1) {
if (opts.remote) { if (opts.remote) {
ret = read(fd_in, buffer, chunk); ret = read(fd_in, buffer, chunk);
@@ -602,7 +608,7 @@ int copy_file(int fd_in, int fd_out, size_t bytes)
written += ret; written += ret;
} }
err: err:
free(buffer); xfree(buffer);
return ret; return ret;
} }