Unverified Commit f6812e7f by Serge Hallyn Committed by GitHub

Merge pull request #2011 from brauner/generic/coverity

coverity: bugfixes
parents fb398f07 2d7bf744
...@@ -599,6 +599,7 @@ static char *lxc_attach_getpwshell(uid_t uid) ...@@ -599,6 +599,7 @@ static char *lxc_attach_getpwshell(uid_t uid)
if (waitpid(pid, &status, 0) < 0) { if (waitpid(pid, &status, 0) < 0) {
if (errno == EINTR) if (errno == EINTR)
goto again; goto again;
free(result);
return NULL; return NULL;
} }
...@@ -607,14 +608,20 @@ static char *lxc_attach_getpwshell(uid_t uid) ...@@ -607,14 +608,20 @@ static char *lxc_attach_getpwshell(uid_t uid)
* don't. * don't.
*/ */
if (!WIFEXITED(status)) if (!WIFEXITED(status)) {
free(result);
return NULL; return NULL;
}
if (WEXITSTATUS(status) != 0) if (WEXITSTATUS(status) != 0) {
free(result);
return NULL; return NULL;
}
if (!found) if (!found) {
free(result);
return NULL; return NULL;
}
return result; return result;
} else { } else {
......
...@@ -555,7 +555,10 @@ static bool find_hierarchy_mountpts( struct cgroup_meta_data *meta_data, char ** ...@@ -555,7 +555,10 @@ static bool find_hierarchy_mountpts( struct cgroup_meta_data *meta_data, char **
} }
} }
k = lxc_array_len((void **)h->all_mount_points); if (h)
k = lxc_array_len((void **)h->all_mount_points);
else
k = 0;
r = lxc_grow_array((void ***)&h->all_mount_points, &h->all_mount_point_capacity, k + 1, 4); r = lxc_grow_array((void ***)&h->all_mount_points, &h->all_mount_point_capacity, k + 1, 4);
if (r < 0) if (r < 0)
goto out; goto out;
......
...@@ -526,6 +526,7 @@ static bool filter_and_set_cpus(char *path, bool am_initialized) ...@@ -526,6 +526,7 @@ static bool filter_and_set_cpus(char *path, bool am_initialized)
copy_parent: copy_parent:
*lastslash = oldv; *lastslash = oldv;
free(fpath);
fpath = must_make_path(path, "cpuset.cpus", NULL); fpath = must_make_path(path, "cpuset.cpus", NULL);
ret = lxc_write_to_file(fpath, cpulist, strlen(cpulist), false); ret = lxc_write_to_file(fpath, cpulist, strlen(cpulist), false);
if (ret < 0) { if (ret < 0) {
...@@ -1748,6 +1749,7 @@ static bool cgfsng_mount(void *hdata, const char *root, int type) ...@@ -1748,6 +1749,7 @@ static bool cgfsng_mount(void *hdata, const char *root, int type)
path2 = must_make_path(controllerpath, h->base_cgroup, d->container_cgroup, NULL); path2 = must_make_path(controllerpath, h->base_cgroup, d->container_cgroup, NULL);
if (mkdir_p(path2, 0755) < 0) { if (mkdir_p(path2, 0755) < 0) {
free(controllerpath); free(controllerpath);
free(path2);
goto bad; goto bad;
} }
......
...@@ -325,7 +325,8 @@ static int lxc_cmd(const char *name, struct lxc_cmd_rr *cmd, int *stopped, ...@@ -325,7 +325,8 @@ static int lxc_cmd(const char *name, struct lxc_cmd_rr *cmd, int *stopped,
*stopped = 1; *stopped = 1;
out: out:
if (!stay_connected || ret <= 0) if (!stay_connected || ret <= 0)
close(client_fd); if (client_fd >= 0)
close(client_fd);
if (stay_connected && ret > 0) if (stay_connected && ret > 0)
cmd->rsp.ret = client_fd; cmd->rsp.ret = client_fd;
......
...@@ -975,7 +975,7 @@ static int lxc_clear_nic(struct lxc_conf *c, const char *key) ...@@ -975,7 +975,7 @@ static int lxc_clear_nic(struct lxc_conf *c, const char *key)
if (!p1 || *(p1+1) == '\0') if (!p1 || *(p1+1) == '\0')
return -1; return -1;
if (!p1 && it) { if (it) {
lxc_remove_nic(it); lxc_remove_nic(it);
} else if (strcmp(p1, ".ipv4") == 0) { } else if (strcmp(p1, ".ipv4") == 0) {
struct lxc_list *it2,*next; struct lxc_list *it2,*next;
......
...@@ -848,10 +848,12 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -848,10 +848,12 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
/* ... otherwise use default_args. */ /* ... otherwise use default_args. */
if (!argv) { if (!argv) {
if (useinit) if (useinit) {
ERROR("No valid init detected");
lxc_free_handler(handler);
return false; return false;
else }
argv = default_args; argv = default_args;
} }
/* I'm not sure what locks we want here.Any? Is liblxc's locking enough /* I'm not sure what locks we want here.Any? Is liblxc's locking enough
......
...@@ -1915,6 +1915,7 @@ static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ...@@ -1915,6 +1915,7 @@ static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *lxc_mkifname(char *template) char *lxc_mkifname(char *template)
{ {
int ret;
unsigned int seed; unsigned int seed;
FILE *urandom; FILE *urandom;
struct ifaddrs *ifa, *ifaddr; struct ifaddrs *ifa, *ifaddr;
...@@ -1926,7 +1927,11 @@ char *lxc_mkifname(char *template) ...@@ -1926,7 +1927,11 @@ char *lxc_mkifname(char *template)
return NULL; return NULL;
/* Get all the network interfaces. */ /* Get all the network interfaces. */
getifaddrs(&ifaddr); ret = getifaddrs(&ifaddr);
if (ret < 0) {
ERROR("%s - Failed to get network interfaces", strerror(errno));
return NULL;
}
/* Initialize the random number generator. */ /* Initialize the random number generator. */
urandom = fopen("/dev/urandom", "r"); urandom = fopen("/dev/urandom", "r");
......
...@@ -226,14 +226,16 @@ restart: ...@@ -226,14 +226,16 @@ restart:
continue; continue;
/* Keep state clients that wait on reboots. */ /* Keep state clients that wait on reboots. */
lxc_list_for_each(cur, &conf->state_clients) { if (conf) {
struct lxc_state_client *client = cur->elem; lxc_list_for_each(cur, &conf->state_clients) {
struct lxc_state_client *client = cur->elem;
if (client->clientfd != fd) if (client->clientfd != fd)
continue; continue;
matched = true; matched = true;
break; break;
}
} }
if (matched) if (matched)
......
...@@ -417,7 +417,7 @@ static int do_clone_ephemeral(struct lxc_container *c, ...@@ -417,7 +417,7 @@ static int do_clone_ephemeral(struct lxc_container *c,
if (!mkdtemp(randname)) if (!mkdtemp(randname))
return -1; return -1;
if (chmod(randname, 0770) < 0) { if (chmod(randname, 0770) < 0) {
remove(randname); (void)remove(randname);
return -1; return -1;
} }
arg->newname = randname + strlen(arg->newpath) + 1; arg->newname = randname + strlen(arg->newpath) + 1;
......
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