From db592aa7256ea36d5dc6d187e674d4680c34cec5 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Sat, 28 Sep 2019 12:18:17 +0200 Subject: Regression fix for realpath() buffer. Let the system allocate realpath() buffers intead of trying to portably derive a buffer size. This was found with default GCC fortify settings on Ubuntu 18.04 and showed with -D_FORTIFY_SOURCE=2 on Fedora, too. --- env.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'env.c') diff --git a/env.c b/env.c index d181945a..a26cf908 100644 --- a/env.c +++ b/env.c @@ -137,9 +137,16 @@ void envquery(int argc, char **argv) * without changing behaviour. */ { - static char _home_abs[_POSIX_PATH_MAX]; - char *tmp = realpath(home, _home_abs); - if (tmp) home = _home_abs; + static char *_home_abs; + char *tmp; + if (_home_abs) free(_home_abs), _home_abs = 0; + tmp = realpath(home, NULL); + if (tmp) { + home = _home_abs = tmp; + } else { + report(stderr, GT_("Cannot find absolute path for user's home directory.\n")); + exit(PS_UNDEFINED); + } } /* compute fetchmail's home directory */ @@ -154,9 +161,16 @@ void envquery(int argc, char **argv) * 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; + static char *_fmhome_abs; + char *tmp; + if (_fmhome_abs) free(_fmhome_abs), _fmhome_abs = 0; + tmp = realpath(fmhome, NULL); + if (tmp) { + fmhome = _fmhome_abs = tmp; + } else { + report(stderr, GT_("Cannot find absolute path for fetchmail's home directory.\n")); + exit(PS_UNDEFINED); + } } #define RCFILE_NAME "fetchmailrc" -- cgit v1.2.3