[CRIU] [PATCH] Fixed NULL_RETURNS issues introduced by remote images code.
Andrei Vagin
avagin at virtuozzo.com
Mon Mar 13 13:37:30 PDT 2017
On Fri, Mar 10, 2017 at 09:43:39AM +0000, Rodrigo Bruno wrote:
> Signed-off-by: Rodrigo Bruno <rbruno at gsd.inesc-id.pt>
> ---
> 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..384ee51 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(".");
> + if (save == NULL) {
> + pr_error("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_error("fchdir to dfd failed");
I think you mean pr_perror ?
> 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_error("fchdir to saved dir failed");
> return -1;
> }
> - close(save);
> + closedir(save);
>
> return ret;
> }
> diff --git a/criu/util.c b/criu/util.c
> index 9fd8ba2..d33ce0e 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_err("Failed to allocate buffer to copy file.\n");
> + return -1;
> + }
> +
> while (1) {
> if (opts.remote) {
> ret = read(fd_in, buffer, chunk);
> --
> 1.9.1
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list