Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverity scan #5

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void buf_put(struct xbuf *xb)
static int bfdopen(struct bfd *f, bool writable)
{
if (buf_get(&f->b)) {
close(f->fd);
close_safe(&f->fd);
return -1;
}

Expand Down
2 changes: 2 additions & 0 deletions cr-restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,8 @@ static int restore_root_task(struct pstree_item *init)

write_stats(RESTORE_STATS);

close_old_fds(NULL);

if (!opts.restore_detach && !opts.exec_cmd)
wait(NULL);

Expand Down
15 changes: 12 additions & 3 deletions files.c
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,18 @@ int close_old_fds(struct pstree_item *me)
return -1;
}

if ((!is_any_service_fd(fd)) && (dirfd(dir) != fd) &&
!inherit_fd_lookup_fd(fd, __FUNCTION__))
close_safe(&fd);
if (dirfd(dir) == fd)
continue;

if (me == NULL)
goto close_next;

if (is_any_service_fd(fd))
continue;
if (inherit_fd_lookup_fd(fd, __FUNCTION__))
continue;
close_next:
close_safe(&fd);
}

closedir(dir);
Expand Down
8 changes: 2 additions & 6 deletions lib/criu.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ int criu_local_add_enable_fs(criu_opts *opts, char *fs)
{
int nr;
char *str = NULL;
char **ptr = NULL;
char **ptr;

str = strdup(fs);
if (!str)
Expand All @@ -625,8 +625,6 @@ int criu_local_add_enable_fs(criu_opts *opts, char *fs)
err:
if (str)
free(str);
if (ptr)
free(ptr);

return -ENOMEM;
}
Expand All @@ -641,7 +639,7 @@ int criu_local_add_skip_mnt(criu_opts *opts, char *mnt)
{
int nr;
char *str = NULL;
char **ptr = NULL;
char **ptr;

str = strdup(mnt);
if (!str)
Expand All @@ -662,8 +660,6 @@ int criu_local_add_skip_mnt(criu_opts *opts, char *mnt)
err:
if (str)
free(str);
if (ptr)
free(ptr);

return -ENOMEM;
}
Expand Down
12 changes: 9 additions & 3 deletions mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,7 @@ static int do_new_mount(struct mount_info *mi)
return -1;
}

pr_err("%s %d %d\n", mi->mountpoint, mi->shared_id, mi->master_id);
if (restore_shared_options(mi, !mi->shared_id && !mi->master_id,
mi->shared_id,
mi->master_id))
Expand Down Expand Up @@ -2282,6 +2283,7 @@ static int do_bind_mount(struct mount_info *mi)
int exit_code = -1;
bool shared = false;
bool master = false;
bool private;
char *mnt_path = NULL;
struct stat st;
bool umount_mnt_path = false;
Expand Down Expand Up @@ -2379,9 +2381,13 @@ static int do_bind_mount(struct mount_info *mi)
* shared - the mount is in the same shared group with mi->bind
* mi->shared_id && !shared - create a new shared group
*/
if (restore_shared_options(mi, force_private_remount || (!shared && !master),
mi->shared_id && !shared,
mi->master_id && !master))
private = (!mi->master_id && !mi->shared_id) || (mi->shared_id && !shared && !mi->master_id);
master = mi->master_id && !master;
shared = mi->shared_id && !shared;
pr_err("%s %d %d\n", mi->mountpoint, mi->shared_id, mi->master_id);
if (restore_shared_options(mi, force_private_remount || private,
shared,
master))
return -1;

mi->mounted = true;
Expand Down
2 changes: 1 addition & 1 deletion page-xfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ int cr_page_server(bool daemon_mode, int cfd)
return ret;

out:
close(sk);
close_safe(&sk);
return -1;
}

Expand Down
18 changes: 17 additions & 1 deletion rst-malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ static int grow_remap(struct rst_mem_type_s *t, int flag, unsigned long size)
{
void *aux;

size = rst_mem_grow(size);
if (size)
size = rst_mem_grow(size);

if (!t->buf)
/*
Expand All @@ -67,6 +68,7 @@ static int grow_remap(struct rst_mem_type_s *t, int flag, unsigned long size)
aux = mmap(NULL, size, PROT_READ | PROT_WRITE,
flag | MAP_ANON, 0, 0);
else
#ifndef CR_DEBUG
/*
* We'll have to remap all objects into restorer
* address space and get their new addresses. Since
Expand All @@ -78,6 +80,17 @@ static int grow_remap(struct rst_mem_type_s *t, int flag, unsigned long size)
*/
aux = mremap(t->buf, t->size,
t->size + size, MREMAP_MAYMOVE);
#else
{
aux = mmap(NULL, t->size + size, PROT_READ | PROT_WRITE,
flag | MAP_ANON, 0, 0);
if (aux == MAP_FAILED)
return -1;
memcpy(aux, t->buf, t->size);
munmap(t->buf, t->size);
pr_err("\n");
}
#endif
if (aux == MAP_FAILED)
return -1;

Expand Down Expand Up @@ -149,6 +162,9 @@ void *rst_mem_alloc(unsigned long size, int type)
pr_perror("Can't grow rst mem");
return NULL;
}
#ifdef CR_DEBUG
t->grow(t, 0);
#endif

ret = t->free_mem;
t->free_mem += size;
Expand Down
6 changes: 6 additions & 0 deletions shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ static int restore_shmem_content(void *addr, struct shmem_info *si)
return -1;

fd_pg = img_raw_fd(pr.pi);
if (fd_pg < 0) {
ret = -1;
goto err;
}

while (1) {
unsigned long vaddr;
unsigned nr_pages;
Expand Down Expand Up @@ -190,6 +195,7 @@ static int restore_shmem_content(void *addr, struct shmem_info *si)
pr.put_pagemap(&pr);
}

err:
pr.close(&pr);
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions test/ext-tty/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
import subprocess
import pty
import os, sys, time
import os, sys, time, signal, pty

master, slave = pty.openpty()

Expand Down Expand Up @@ -29,7 +29,7 @@

os.close(new_master)
_, status = os.wait()
if not os.WIFSIGNALED(status) or not os.WTERMSIG(status):
if not os.WIFSIGNALED(status) or os.WTERMSIG(status) != signal.SIGHUP:
print status
sys.exit(1)

Expand Down
7 changes: 6 additions & 1 deletion test/zdtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,12 @@ def get_visible_state(test):
try:
r = re.compile("^\S+\s\S+\s\S+\s(\S+)\s(\S+)")
for m in open("/proc/%s/root/proc/%s/mountinfo" % (test.getpid(), pid)):
cmounts.append(r.match(m).groups())
g = list(r.match(m).groups())
if "master" in m:
g.append("master")
if "shared" in m:
g.append("shared")
cmounts.append(tuple(g))
except IOError, e:
if e.errno != errno.EINVAL:
raise e
Expand Down
1 change: 1 addition & 0 deletions test/zdtm/live/static/chroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ int main(int argc, char **argv)

res = ERR_PIPES;
read(pipe_prep[0], &res, 1);
read(pipe_prep[0], &res, 1); /* wait when pipe_prep[] will be closed */
if (res != SUCCESS) {
if (res == ERR_PIPES)
pr_perror("broken pipes");
Expand Down
52 changes: 0 additions & 52 deletions test/zdtm/live/static/mountpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const char *test_author = "Pavel Emelianov <[email protected]>";

#define MPTS_ROOT "/zdtm_mpts/"

static char buf[1024];

#define NS_STACK_SIZE 4096
/* All arguments should be above stack, because it grows down */
struct ns_exec_args {
Expand Down Expand Up @@ -76,64 +74,14 @@ int ns_child(void *_arg)

int main(int argc, char **argv)
{
FILE *f;
int fd, tmpfs_fd, have_bfmtm = 0;
unsigned fs_cnt, fs_cnt_last = 0;
struct ns_exec_args args;
pid_t pid = -1;

test_init(argc, argv);

task_waiter_init(&t);

again:
fs_cnt = 0;
f = fopen("/proc/self/mountinfo", "r");
if (!f) {
fail("Can't open mountinfo");
return -1;
}

if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL)) {
pr_perror("Can't remount / with MS_PRIVATE");
return -1;
}

while (fgets(buf, sizeof(buf), f) != NULL) {
char *mp = buf, *end;

mp = strchr(mp, ' ') + 1;
mp = strchr(mp, ' ') + 1;
mp = strchr(mp, ' ') + 1;
mp = strchr(mp, ' ') + 1;
end = strchr(mp, ' ');
*end = '\0';

if (!strcmp(mp, "/"))
continue;
if (!strcmp(mp, "/proc"))
continue;

if (umount(mp))
test_msg("umount(`%s') failed: %m\n", mp);

fs_cnt++;
}

fclose(f);

if (fs_cnt == 0)
goto done;

if (fs_cnt != fs_cnt_last) {
fs_cnt_last = fs_cnt;
goto again;
}

fail("Can't umount all the filesystems");
return -1;

done:
rmdir(MPTS_ROOT);
if (mkdir(MPTS_ROOT, 0600) < 0) {
fail("Can't make zdtm_sys");
Expand Down