[CRIU] [PATCH v2] Fixed NULL_RETURNS issues introduced by remote images code.

Andrei Vagin avagin at virtuozzo.com
Wed Mar 15 18:45:52 PDT 2017


On Tue, Mar 14, 2017 at 11:18:30PM +0000, rodrigo-bruno wrote:
> ---
>  criu/image.c | 15 ++++++++++-----
>  criu/util.c  |  5 +++++
>  2 files changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/criu/image.c b/criu/image.c
> index 57d3c7b..e1bcea5 100644
> --- a/criu/image.c
> +++ b/criu/image.c
> @@ -332,9 +332,14 @@ int do_open_remote_image(int dfd, char *path, int flags)
>  	/* When using namespaces, the current dir is changed so we need to
>  	 * change to previous working dir and back to correctly open the image
>  	 * proxy and cache sockets. */
> -	int save = dirfd(opendir("."));
> +	DIR *save = opendir(".");

you use only a file descriptor, so I think you can use open()

	int old_cwd;

	old_cwd = open(".", O_PATH);
	if (old_cwd < ) {
		...


> +	if (save == NULL) {
> +		pr_perror("unable to open current working directory");
> +		return -1;
> +	}
> +
>  	if (fchdir(get_service_fd(IMG_FD_OFF)) < 0) {
> -		pr_debug("fchdir to dfd failed!\n");
> +		pr_perror("fchdir to dfd failed!\n");
>  		return -1;
>  	}
>  
> @@ -352,11 +357,11 @@ int do_open_remote_image(int dfd, char *path, int flags)
>  		ret = write_remote_image_connection(snapshot_id, path, O_WRONLY);
>  	}
>  
> -	if (fchdir(save) < 0) {
> -		pr_debug("fchdir to save failed!\n");
> +	if (fchdir(dirfd(save)) < 0) {
> +		pr_perror("fchdir to save failed");
>  		return -1;
>  	}
> -	close(save);
> +	closedir(save);
>  
>  	return ret;
>  }
> diff --git a/criu/util.c b/criu/util.c
> index 9fd8ba2..4156bf2 100644
> --- a/criu/util.c
> +++ b/criu/util.c
> @@ -522,6 +522,11 @@ int copy_file(int fd_in, int fd_out, size_t bytes)
>  	char *buffer = (char*) malloc(chunk);
>  	ssize_t ret;
>  
> +	if (buffer == NULL) {
> +		pr_perror("failed to allocate buffer to copy file");
> +		return -1;
> +	}
> +
>  	while (1) {
>  		if (opts.remote) {
>  			ret = read(fd_in, buffer, chunk);
> -- 
> 2.1.4
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list