Store the initial working directory, expand $initial_cwd. Bug 1805 exim-4_82_1+CVE-2016-1531 github/exim-4_82_1+CVE-2016-1531
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Wed, 9 Mar 2016 10:13:42 +0000 (11:13 +0100)
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Sat, 12 Mar 2016 22:30:45 +0000 (23:30 +0100)
(cherry picked from commit 3615fa9a06356891367c66ed284cef9db5cefca3)

doc/doc-docbook/spec.xfpt
doc/doc-txt/NewStuff
src/src/exim.c
src/src/expand.c
src/src/globals.c
src/src/globals.h

index 22ccf86e9a61a79d086ba8aab5528b5b63ce7e44..9c4f78a1fc3239c6bb92e4bd8e9ce8c312dcf39d 100644 (file)
@@ -11276,6 +11276,12 @@ the result, the name is not accepted, and &$host_lookup_deferred$& is set to
 .vindex "&$host_lookup_failed$&"
 See &$host_lookup_deferred$&.
 
+.vitem &$initial_cwd$&
+.vindex "&$initial_cwd$&
+This variable contains the full path name of the initial working
+directory of the current Exim process. This may differ from the current
+working directory, as Exim changes this to "/" during early startup, and
+to &$spool_directory$& later.
 
 .vitem &$inode$&
 .vindex "&$inode$&"
index d308f0485413a462739206da60f1d75889d30aa5..9d07a2d706fa3ba16482485cd65794232df544cb 100644 (file)
@@ -6,6 +6,8 @@ Before a formal release, there may be quite a lot of detail so that people can
 test from the snapshots or the CVS before the documentation is updated. Once
 the documentation is updated, this file is reduced to a short list.
 
+ 9. New $initial_cwd expansion variable.
+
 Version 4.82
 ------------
 
index 807f1ea87f4a8666de8ac21b67f28e6c002ba3b0..e3318f70c1def8e8842986b5f02d7721476133ea 100644 (file)
@@ -3655,6 +3655,13 @@ if (Uchdir("/") < 0)
     exit(EXIT_FAILURE);
   }
 
+/* Store the initial cwd before we change directories */
+if ((initial_cwd = getcwd(NULL, 0)) == NULL)
+  {
+  perror("exim: can't get the current working directory");
+  exit(EXIT_FAILURE);
+  }
+
 readconf_main();
 
 if (cleanup_environment() == FALSE)
@@ -3931,9 +3938,10 @@ if (((debug_selector & D_any) != 0 || (log_extra_selector & LX_arguments) != 0)
   {
   int i;
   uschar *p = big_buffer;
-  char * dummy;
   Ustrcpy(p, "cwd= (failed)");
-  dummy = /* quieten compiler */ getcwd(CS p+4, big_buffer_size - 4);
+
+  Ustrncpy(p + 4, initial_cwd, big_buffer_size-5);
+
   while (*p) p++;
   (void)string_format(p, big_buffer_size - (p - big_buffer), " %d args:", argc);
   while (*p) p++;
index 5a764d3df3071637c1a07d115fb24aebf48a5e15..8bf84b946ec0ff306bdd9f4c088867ee737ae157 100644 (file)
@@ -487,6 +487,7 @@ static var_entry var_table[] = {
   { "host_data",           vtype_stringptr,   &host_data },
   { "host_lookup_deferred",vtype_int,         &host_lookup_deferred },
   { "host_lookup_failed",  vtype_int,         &host_lookup_failed },
+  { "initial_cwd",         vtype_stringptr,   &initial_cwd },
   { "inode",               vtype_ino,         &deliver_inode },
   { "interface_address",   vtype_stringptr,   &interface_address },
   { "interface_port",      vtype_int,         &interface_port },
index e5ac8d679f2512e20a32f63d870531c65c55b2e3..09bc5934dc9f4d932857a0be7af97c4d4e9caa34 100644 (file)
@@ -733,6 +733,7 @@ BOOL    ignore_fromline_local  = FALSE;
 uschar *ignore_fromline_hosts  = NULL;
 BOOL    inetd_wait_mode        = FALSE;
 int     inetd_wait_timeout     = -1;
+uschar *initial_cwd            = NULL;
 uschar *interface_address      = NULL;
 int     interface_port         = -1;
 BOOL    is_inetd               = FALSE;
index 9c7238212483d29381f629ede0fadcc39c247ef2..bca1eadacea7b7414d0e653eba3dfb8dc962d2c3 100644 (file)
@@ -466,6 +466,7 @@ extern BOOL    ignore_fromline_local;  /* Local SMTP ignore fromline */
 extern uschar *ignore_fromline_hosts;  /* Hosts permitted to send "From " */
 extern BOOL    inetd_wait_mode;        /* Whether running in inetd wait mode */
 extern int     inetd_wait_timeout;     /* Timeout for inetd wait mode */
+extern uschar *initial_cwd;            /* The directory we where in at startup */
 extern BOOL    is_inetd;               /* True for inetd calls */
 extern uschar *iterate_item;           /* Item from iterate list */