]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Don't crash if getenv() is called after process_title_deinit() with Linux/OSX...
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 19 Jan 2016 18:45:27 +0000 (20:45 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 19 Jan 2016 18:45:27 +0000 (20:45 +0200)
Right now the only known issue is GNUTLS's lib_deinit():

e = getenv("GNUTLS_NO_EXPLICIT_INIT");

But we likely never want that to be set. Alternative ways to solve this are
more annoying than our clearing the environment. Libraries probably shouldn't
rely on it much anyway, because some parts of Dovecot clear the whole
environment while running.

src/lib/process-title.c

index bda21717cd83d1a34c515606aab5468df5a27b58..14d203e8d193b710d3a0d53f275c69f2e2ddf25c 100644 (file)
@@ -147,7 +147,19 @@ void process_title_set(const char *title ATTR_UNUSED)
 void process_title_deinit(void)
 {
 #ifdef PROCTITLE_HACK
+       char ***environ_p = env_get_environ_p();
+
        free(argv_memblock);
        free(environ_memblock);
+
+       /* Environment is no longer usable. Make sure we won't crash in case
+          some library's deinit function still calls getenv(). This code was
+          mainly added because of GNUTLS where we don't really care about the
+          getenv() call.
+
+          Alternatively we could remove the free() calls above, but that would
+          annoy memory leak checking tools. Also we could attempt to restore
+          the environ_p to its original state, but that's a bit complicated. */
+       *environ_p = NULL;
 #endif
 }