aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2019-09-27 18:45:12 +0200
committerMatthias Andree <matthias.andree@gmx.de>2019-09-27 18:47:14 +0200
commitb2f24e95ba3103f8002578f4c2607d5744b6007c (patch)
tree105dc79b988071849db6b11adab8d7544fb342cd
parent7b6543d77dae0d9dc8cf8f4b46a08698da28876e (diff)
downloadfetchmail-b2f24e95ba3103f8002578f4c2607d5744b6007c.tar.gz
fetchmail-b2f24e95ba3103f8002578f4c2607d5744b6007c.tar.bz2
fetchmail-b2f24e95ba3103f8002578f4c2607d5744b6007c.zip
env.c: make FETCHMAILHOME (fmhome) absolute.
If FETCHMAILHOME is specified as relative path, then it can become the victim of a chdir("/") that happens in daemon mode, so that switching to daemon mode will change behaviour of FETCHMAILHOME. Reported by Alex Andreotti, Debian Bug #941129.
-rw-r--r--NEWS3
-rw-r--r--env.c15
2 files changed, 17 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 006a5969..1a4ea966 100644
--- a/NEWS
+++ b/NEWS
@@ -188,6 +188,9 @@ fetchmail-6.4.0 (not yet released):
that quoted-printable-encoded multipart messages can get decoded.
(Regression in 5.0.0 on 1999-03-27, as a side effect of a PGP-mimedecode fix
attributed to Henrik Storner.)
+* FETCHMAILHOME can now safely be a relative path, which will be qualified
+ through realpath(). Previously, it had to be absolute in daemon mode.
+ Reported by Alex Andreotti, Debian Bug#941129.
## UPDATED TRANSLATIONS - THANKS TO:
* CS: Petr Pisar <petr.pisar@atlas.cz> [Czech]
diff --git a/env.c b/env.c
index f1fb2cdf..06cfcb38 100644
--- a/env.c
+++ b/env.c
@@ -29,6 +29,7 @@
#if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS) && defined(HAVE_STRFTIME)
#include <locale.h>
#endif
+#include <limits.h>
#ifndef HAVE_DECL_GETENV
extern char *getenv(const char *); /* needed on sysV68 R3V7.1. */
@@ -115,8 +116,20 @@ void envquery(int argc, char **argv)
home = xstrdup(pwp->pw_dir);
/* compute fetchmail's home directory */
- if (!(fmhome = getenv("FETCHMAILHOME")))
+ fmhome = getenv("FETCHMAILHOME");
+ if (NULL == fmhome) {
fmhome = home;
+ }
+ /* and make it an absolute path, so we
+ * can optionally chdir("/") later in daemonize()
+ * without changing behaviour.
+ * This is to fix Debian Bug#941129 by Alex Andreotti.
+ */
+ {
+ static char _fmhome_abs[_POSIX_PATH_MAX];
+ char *tmp = realpath(fmhome, _fmhome_abs);
+ if (tmp) fmhome = _fmhome_abs;
+ }
#define RCFILE_NAME "fetchmailrc"
/*