Commit 6b9324bd by Stéphane Graber

coverity: Do chdir following chroot

We used to do chdir(path), chroot(path). That's correct but not properly handled coverity, so do chroot(path), chdir("/") instead as that's the recommended way. Signed-off-by: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent 4473e38b
...@@ -1516,14 +1516,14 @@ static int chroot_into_slave(struct lxc_conf *conf) ...@@ -1516,14 +1516,14 @@ static int chroot_into_slave(struct lxc_conf *conf)
SYSERROR("Failed to make tmp-/ at %s rslave", path); SYSERROR("Failed to make tmp-/ at %s rslave", path);
return -1; return -1;
} }
if (chdir(path)) {
SYSERROR("Failed to chdir into tmp-/");
return -1;
}
if (chroot(path)) { if (chroot(path)) {
SYSERROR("Failed to chroot into tmp-/"); SYSERROR("Failed to chroot into tmp-/");
return -1; return -1;
} }
if (chdir("/")) {
SYSERROR("Failed to chdir into tmp-/");
return -1;
}
INFO("Chrooted into tmp-/ at %s", path); INFO("Chrooted into tmp-/ at %s", path);
return 0; return 0;
} }
......
...@@ -3142,9 +3142,9 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add, ...@@ -3142,9 +3142,9 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add,
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= MAXPATHLEN)
return false; return false;
if (chdir(chrootpath) < 0) if (chroot(chrootpath) < 0)
exit(1); exit(1);
if (chroot(".") < 0) if (chdir("/") < 0)
exit(1); exit(1);
/* remove path if it exists */ /* remove path if it exists */
if(faccessat(AT_FDCWD, path, F_OK, AT_SYMLINK_NOFOLLOW) == 0) { if(faccessat(AT_FDCWD, path, F_OK, AT_SYMLINK_NOFOLLOW) == 0) {
......
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