From: Aki Tuomi Date: Thu, 14 Sep 2017 10:34:22 +0000 (+0300) Subject: lib: chdir to / after chroot X-Git-Tag: 2.3.0.rc1~1021 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a2262007b0ccca11703a61788b77fd48b4aebad;p=thirdparty%2Fdovecot%2Fcore.git lib: chdir to / after chroot Makes static analyzers more happy --- diff --git a/src/lib/restrict-access.c b/src/lib/restrict-access.c index 7caf7f64fe..7441cef11f 100644 --- a/src/lib/restrict-access.c +++ b/src/lib/restrict-access.c @@ -325,18 +325,17 @@ void restrict_access(const struct restrict_access_settings *set, if (chroot(set->chroot_dir) != 0) i_fatal("chroot(%s) failed: %m", set->chroot_dir); + /* makes static analyzers happy, and is more secure */ + if (chdir("/") != 0) + i_fatal("chdir(/) failed: %m"); + chroot_dir = i_strdup(set->chroot_dir); if (home != NULL) { if (chdir(home) < 0) { i_error("chdir(%s) failed: %m", home); - home = NULL; } } - if (home == NULL) { - if (chdir("/") != 0) - i_fatal("chdir(/) failed: %m"); - } } /* uid last */