Only chdir to cwd if it is different from the current cwd or there
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 8 Nov 2010 21:40:11 +0000 (16:40 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 8 Nov 2010 21:40:11 +0000 (16:40 -0500)
is a new root (chroot).

src/sudo.c

index 370e993ff2e3d3b53fa4b690577c335d171a75a1..9d1df4d21d580ff454940bce0c91fd5b7d8985ec 100644 (file)
@@ -848,12 +848,17 @@ exec_setup(struct command_details *details, const char *ptyname, int ptyfd)
     }
 #endif /* !HAVE_SETRESUID && !HAVE_SETREUID */
 
-    /* Set cwd after uid to avoid permissions problems. */
+    /*
+     * Only change cwd if we have chroot()ed or the policy modules
+     * specifies a different cwd.  Must be done after uid change.
+     */
     if (details->cwd) {
-       /* Note: cwd is relative to the new root, if any. */
-       if (chdir(details->cwd) != 0) {
-           warning("unable to change directory to %s", details->cwd);
-           goto done;
+       if (details->chroot || strcmp(details->cwd, user_details.cwd) != 0) {
+           /* Note: cwd is relative to the new root, if any. */
+           if (chdir(details->cwd) != 0) {
+               warning("unable to change directory to %s", details->cwd);
+               goto done;
+           }
        }
     }