If a call to chroot is not followed by a call to chdir("/") the chroot jail
confinement can be violated. See also CWE-243.
CID: 360718
CID: 360800
Reference: http://cwe.mitre.org/data/definitions/243.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
if (chroot(".") < 0)
err(EXIT_FAILURE, _("chroot failed"));
+ if (chdir("/"))
+ err(EXIT_FAILURE, _("cannot change directory to %s"), "/");
close(root_fd);
root_fd = -1;
return -1;
}
+ if (chdir("/")) {
+ close(cfd);
+ warn(_("cannot change directory to %s"), "/");
+ return -1;
+ }
+
pid = fork();
if (pid <= 0) {
struct statfs stfs;