]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Fix mail_storage_set_critical() when input parameter is an old internal...
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 24 May 2017 18:29:49 +0000 (21:29 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 24 May 2017 18:30:34 +0000 (21:30 +0300)
This could have caused garbage in the error string.

src/lib-storage/mail-storage.c

index 0ba25436cad4f90f30fa6f3c13480efcaf4cb986..7ad9a1fc51e5a7f4b86e62be716daa8257b52afb 100644 (file)
@@ -518,15 +518,19 @@ void mail_storage_set_internal_error(struct mail_storage *storage)
 void mail_storage_set_critical(struct mail_storage *storage,
                               const char *fmt, ...)
 {
+       char *old_error = storage->last_internal_error;
        va_list va;
 
-       i_free(storage->last_internal_error);
        va_start(va, fmt);
        storage->last_internal_error = i_strdup_vprintf(fmt, va);
        va_end(va);
        storage->last_error_is_internal = TRUE;
        i_error("%s", storage->last_internal_error);
 
+       /* free the old_error only after the new error is generated, because
+          the old_error may be one of the parameters. */
+       i_free(old_error);
+
        /* critical errors may contain sensitive data, so let user
           see only "Internal error" with a timestamp to make it
           easier to look from log files the actual error message. */