From 1e20fa6c69a886a568f2c9811603ecb3d90e790c Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan.bosch@dovecot.fi>
Date: Sat, 25 Nov 2017 11:22:56 +0100
Subject: [PATCH] lib-sieve: util: edit-header: Fixed potential NULL
 dereference in edit_mail_istream_read().

The merge_from_parent() function may not actually read anything, potentially leaving the stream buffer unassigned.
Problem found by Coverity.
---
 src/lib-sieve/util/edit-mail.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/lib-sieve/util/edit-mail.c b/src/lib-sieve/util/edit-mail.c
index 1c7423067..7cccb9790 100644
--- a/src/lib-sieve/util/edit-mail.c
+++ b/src/lib-sieve/util/edit-mail.c
@@ -1970,7 +1970,8 @@ static ssize_t edit_mail_istream_read(struct istream_private *stream)
 
 			if ( append_v_offset == hdr_size - 1 ) {
 				/* Strip final CR too when it is present */
-				if ( stream->buffer[stream->pos-1] == '\r' ) {
+				if ( stream->buffer != NULL &&
+					stream->buffer[stream->pos-1] == '\r' ) {
 					stream->pos--;
 					ret--;
 				}
-- 
GitLab