Unverified Commit cebc88c1 by Christian Brauner Committed by GitHub

Merge pull request #2394 from 2xsec/coverity

coverity: #1425747
parents a810dc80 92838873
...@@ -868,14 +868,14 @@ static bool criu_ok(struct lxc_container *c, char **criu_version) ...@@ -868,14 +868,14 @@ static bool criu_ok(struct lxc_container *c, char **criu_version)
{ {
struct lxc_list *it; struct lxc_list *it;
if (!criu_version_ok(criu_version))
return false;
if (geteuid()) { if (geteuid()) {
ERROR("Must be root to checkpoint"); ERROR("Must be root to checkpoint");
return false; return false;
} }
if (!criu_version_ok(criu_version))
return false;
/* We only know how to restore containers with veth networks. */ /* We only know how to restore containers with veth networks. */
lxc_list_for_each(it, &c->lxc_conf->network) { lxc_list_for_each(it, &c->lxc_conf->network) {
struct lxc_netdev *n = it->elem; struct lxc_netdev *n = it->elem;
...@@ -887,6 +887,10 @@ static bool criu_ok(struct lxc_container *c, char **criu_version) ...@@ -887,6 +887,10 @@ static bool criu_ok(struct lxc_container *c, char **criu_version)
break; break;
default: default:
ERROR("Found un-dumpable network: %s (%s)", lxc_net_type_to_str(n->type), n->name); ERROR("Found un-dumpable network: %s (%s)", lxc_net_type_to_str(n->type), n->name);
if (criu_version) {
free(*criu_version);
*criu_version = NULL;
}
return false; return false;
} }
} }
...@@ -1239,6 +1243,7 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op ...@@ -1239,6 +1243,7 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op
ret = pipe(criuout); ret = pipe(criuout);
if (ret < 0) { if (ret < 0) {
SYSERROR("pipe() failed"); SYSERROR("pipe() failed");
free(criu_version);
return false; return false;
} }
...@@ -1299,6 +1304,7 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op ...@@ -1299,6 +1304,7 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op
if (w == -1) { if (w == -1) {
SYSERROR("waitpid"); SYSERROR("waitpid");
close(criuout[0]); close(criuout[0]);
free(criu_version);
return false; return false;
} }
...@@ -1327,6 +1333,8 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op ...@@ -1327,6 +1333,8 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op
if (!ret) if (!ret)
ERROR("criu output: %s", buf); ERROR("criu output: %s", buf);
free(criu_version);
return ret; return ret;
} }
fail: fail:
...@@ -1366,9 +1374,6 @@ bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts) ...@@ -1366,9 +1374,6 @@ bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts)
int pipefd[2]; int pipefd[2];
char *criu_version = NULL; char *criu_version = NULL;
if (!criu_ok(c, &criu_version))
return false;
if (geteuid()) { if (geteuid()) {
ERROR("Must be root to restore"); ERROR("Must be root to restore");
return false; return false;
...@@ -1379,10 +1384,17 @@ bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts) ...@@ -1379,10 +1384,17 @@ bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts)
return false; return false;
} }
if (!criu_ok(c, &criu_version)) {
close(pipefd[0]);
close(pipefd[1]);
return false;
}
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0) {
close(pipefd[0]); close(pipefd[0]);
close(pipefd[1]); close(pipefd[1]);
free(criu_version);
return false; return false;
} }
...@@ -1393,6 +1405,7 @@ bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts) ...@@ -1393,6 +1405,7 @@ bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts)
} }
close(pipefd[1]); close(pipefd[1]);
free(criu_version);
nread = read(pipefd[0], &status, sizeof(status)); nread = read(pipefd[0], &status, sizeof(status));
close(pipefd[0]); close(pipefd[0]);
......
...@@ -1384,7 +1384,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, ...@@ -1384,7 +1384,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath,
ret = mount(src, bdev->dest, "bind", MS_BIND | MS_REC, NULL); ret = mount(src, bdev->dest, "bind", MS_BIND | MS_REC, NULL);
if (ret < 0) { if (ret < 0) {
ERROR("Failed to mount rootfs"); ERROR("Failed to mount rootfs");
return -1; _exit(EXIT_FAILURE);
} }
} else { } else {
ret = bdev->ops->mount(bdev); ret = bdev->ops->mount(bdev);
......
...@@ -216,18 +216,11 @@ int lxc_monitor_open(const char *lxcpath) ...@@ -216,18 +216,11 @@ int lxc_monitor_open(const char *lxcpath)
if (lxc_monitor_sock_name(lxcpath, &addr) < 0) if (lxc_monitor_sock_name(lxcpath, &addr) < 0)
return -1; return -1;
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
ERROR("Failed to create socket: %s.", strerror(errno));
return -1;
}
len = strlen(&addr.sun_path[1]); len = strlen(&addr.sun_path[1]);
DEBUG("opening monitor socket %s with len %zu", &addr.sun_path[1], len); DEBUG("opening monitor socket %s with len %zu", &addr.sun_path[1], len);
if (len >= sizeof(addr.sun_path) - 1) { if (len >= sizeof(addr.sun_path) - 1) {
errno = ENAMETOOLONG; errno = ENAMETOOLONG;
ERROR("name of monitor socket too long (%zu bytes): %s", len, strerror(errno)); ERROR("name of monitor socket too long (%zu bytes): %s", len, strerror(errno));
close(fd);
return -1; return -1;
} }
......
...@@ -342,16 +342,9 @@ static int lxc_monitor_open(const char *lxcpath) ...@@ -342,16 +342,9 @@ static int lxc_monitor_open(const char *lxcpath)
if (lxc_monitor_sock_name(lxcpath, &addr) < 0) if (lxc_monitor_sock_name(lxcpath, &addr) < 0)
return -1; return -1;
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
fprintf(stderr, "Failed to create socket: %s\n", strerror(errno));
return -errno;
}
len = strlen(&addr.sun_path[1]); len = strlen(&addr.sun_path[1]);
if (len >= sizeof(addr.sun_path) - 1) { if (len >= sizeof(addr.sun_path) - 1) {
errno = ENAMETOOLONG; errno = ENAMETOOLONG;
close(fd);
fprintf(stderr, "name of monitor socket too long (%zu bytes): %s\n", len, strerror(errno)); fprintf(stderr, "name of monitor socket too long (%zu bytes): %s\n", len, strerror(errno));
return -errno; return -errno;
} }
......
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