[packages/dovecot-pigeonhole] Rel 3. Backport pigeonhole fixes from 2.4.5

arekm arekm at pld-linux.org
Thu Oct 29 08:32:25 CET 2026


commit 554c2b3c6d0c10ebecd3fa65868ed0eca334fdd7
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Thu Oct 29 08:32:14 2026 +0100

    Rel 3. Backport pigeonhole fixes from 2.4.5
    
    Fixes CVE-2026-42007, CVE-2026-40013, CVE-2026-33605.

 CVE-2026-33605.patch    |  34 ++++++
 CVE-2026-40013.patch    |  31 +++++
 CVE-2026-42007.patch    | 305 ++++++++++++++++++++++++++++++++++++++++++++++++
 dovecot-pigeonhole.spec |  15 +--
 4 files changed, 378 insertions(+), 7 deletions(-)
---
diff --git a/dovecot-pigeonhole.spec b/dovecot-pigeonhole.spec
index ab12d34..804546a 100644
--- a/dovecot-pigeonhole.spec
+++ b/dovecot-pigeonhole.spec
@@ -7,7 +7,7 @@ Summary:	Sieve plugin for dovecot
 Summary(pl.UTF-8):	Wtyczka Sieve i Managesieve dla dovecota
 Name:		dovecot-pigeonhole
 Version:	%{dovecot_series}_%{pigeonhole_version}
-Release:	2
+Release:	3
 License:	LGPL
 Group:		Daemons
 Source0:	https://pigeonhole.dovecot.org/releases/%{dovecot_series}/dovecot-%{dovecot_series}-pigeonhole-%{pigeonhole_version}.tar.gz
@@ -19,15 +19,13 @@ Patch0:		CVE-2025-59032.patch
 Patch1:		CVE-2026-27857.patch
 Patch2:		CVE-2026-27858.patch
 Patch3:		CVE-2026-40016.patch
-URL:		http://pigeonhole.dovecot.org/
-BuildRequires:	autoconf
-BuildRequires:	automake
-BuildRequires:	bison
+Patch4:		CVE-2026-40013.patch
+Patch5:		CVE-2026-33605.patch
+Patch6:		CVE-2026-42007.patch
+URL:		https://pigeonhole.dovecot.org/
 #BuildRequires:	dovecot-devel >= 1:%{dovecot_series}
 # CVE-2026-27857 changed the imap_parser_create() API in lib-imap
 BuildRequires:	dovecot-devel >= 1:2.3.21.1-9
-BuildRequires:	flex
-BuildRequires:	libtool
 %requires_eq_to	dovecot dovecot-devel
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
@@ -69,6 +67,9 @@ Ten pakiet zawiera demona Manage Sieve dla dovecot.
 %patch -P1 -p1
 %patch -P2 -p1
 %patch -P3 -p1
+%patch -P4 -p1
+%patch -P5 -p1
+%patch -P6 -p1
 
 %build
 %configure \
diff --git a/CVE-2026-33605.patch b/CVE-2026-33605.patch
new file mode 100644
index 0000000..77639a9
--- /dev/null
+++ b/CVE-2026-33605.patch
@@ -0,0 +1,34 @@
+CVE-2026-33605: lone CR before authentication crashes or wedges
+managesieve-login.
+Upstream https://github.com/dovecot/pigeonhole/commit/14c28ca9c4aab11b1074c629bb744c4741434148
+and https://github.com/dovecot/pigeonhole/commit/77bf1049ab8652b125e02ed00a15e1dd2e1feb98
+via Debian trixie 1:2.4.1+dfsg1-6+deb13u7; 2.3 has client->common.input.
+
+--- a/src/lib-managesieve/managesieve-parser.c
++++ b/src/lib-managesieve/managesieve-parser.c
+@@ -441,6 +441,15 @@ static bool managesieve_parser_read_arg(struct managesieve_parser *parser)
+ 
+ 		switch (data[0]) {
+ 		case '\r':
++			if (data_size == 1) {
++				/* Wait for LF */
++				return FALSE;
++			}
++			if (data[1] != '\n') {
++				parser->error = "CR sent without LF";
++				return FALSE;
++			}
++			/* Fall through */
+ 		case '\n':
+ 			/* Unexpected end of line */
+ 			parser->eol = TRUE;
+--- a/src/managesieve-login/client.c
++++ b/src/managesieve-login/client.c
+@@ -49,6 +49,7 @@ bool client_skip_line(struct managesieve_client *client)
+ 		}
+ 	}
+ 
++	i_stream_skip(client->common.input, data_size);
+ 	return FALSE;
+ }
+ 
diff --git a/CVE-2026-40013.patch b/CVE-2026-40013.patch
new file mode 100644
index 0000000..39c7606
--- /dev/null
+++ b/CVE-2026-40013.patch
@@ -0,0 +1,31 @@
+CVE-2026-40013: out-of-bounds stack write in sieve_binary_emit_integer()
+compiling a script with a 64-bit numeric literal (ManageSieve crash).
+Upstream https://github.com/dovecot/pigeonhole/commit/ebbf9fe427aa4f3c543abd4ef80564ff173856bc
+via Debian trixie 1:2.4.1+dfsg1-6+deb13u7.
+
+--- a/src/lib-sieve/sieve-binary-code.c
++++ b/src/lib-sieve/sieve-binary-code.c
+@@ -124,7 +124,7 @@ sieve_size_t sieve_binary_emit_integer(struct sieve_binary_block *sblock,
+ 				       sieve_number_t integer)
+ {
+ 	sieve_size_t address = _sieve_binary_block_get_size(sblock);
+-	uint8_t buffer[sizeof(sieve_number_t) + 1];
++	uint8_t buffer[sizeof(sieve_number_t) * 8 / 7 + 1];
+ 	int bufpos = sizeof(buffer) - 1;
+ 
+ 	/* Encode last byte [0xxxxxxx]; msb == 0 marks the last byte */
+--- a/tests/test-size.svtest
++++ b/tests/test-size.svtest
+@@ -72,3 +72,12 @@ test "Exact size" {
+ 	}
+ }
+ 
++/*
++ * TEST: Extreme size
++ */
++
++test "Extreme size" {
++	if size :over 18446744073709551615 {
++		test_fail "size :over matched extreme size";
++	}
++}
diff --git a/CVE-2026-42007.patch b/CVE-2026-42007.patch
new file mode 100644
index 0000000..16fd4ce
--- /dev/null
+++ b/CVE-2026-42007.patch
@@ -0,0 +1,305 @@
+CVE-2026-42007: editheader use-after-free on stale header index and
+heap overread on NUL bytes in header values (edit-mail).
+Upstream https://github.com/dovecot/pigeonhole/commit/69bac9cd6d4ac09100ee50c98052be1437f1da29
+and https://github.com/dovecot/pigeonhole/commit/cd9870e7f87e9d91e9d05b402da653df845b4f8f
+via Debian trixie 1:2.4.1+dfsg1-6+deb13u7; unit test adapted to 2.3
+test_init(), Makefile.in updated as the build does not run automake.
+
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -155,10 +155,12 @@ test_cases = \
+ 	tests/extensions/ihave/restrictions.svtest \
+ 	tests/extensions/editheader/addheader.svtest \
+ 	tests/extensions/editheader/deleteheader.svtest \
++	tests/extensions/editheader/deleteheader-snapshot.svtest \
+ 	tests/extensions/editheader/alternating.svtest \
+ 	tests/extensions/editheader/utf8.svtest \
+ 	tests/extensions/editheader/protected.svtest \
+ 	tests/extensions/editheader/errors.svtest \
++	tests/extensions/editheader/nul-value.svtest \
+ 	tests/extensions/editheader/execute.svtest \
+ 	tests/extensions/duplicate/errors.svtest \
+ 	tests/extensions/duplicate/execute.svtest \
+--- a/Makefile.in
++++ b/Makefile.in
+@@ -564,10 +564,12 @@ test_cases = \
+ 	tests/extensions/ihave/restrictions.svtest \
+ 	tests/extensions/editheader/addheader.svtest \
+ 	tests/extensions/editheader/deleteheader.svtest \
++	tests/extensions/editheader/deleteheader-snapshot.svtest \
+ 	tests/extensions/editheader/alternating.svtest \
+ 	tests/extensions/editheader/utf8.svtest \
+ 	tests/extensions/editheader/protected.svtest \
+ 	tests/extensions/editheader/errors.svtest \
++	tests/extensions/editheader/nul-value.svtest \
+ 	tests/extensions/editheader/execute.svtest \
+ 	tests/extensions/duplicate/errors.svtest \
+ 	tests/extensions/duplicate/execute.svtest \
+--- a/src/lib-sieve/util/edit-mail.c
++++ b/src/lib-sieve/util/edit-mail.c
+@@ -550,8 +550,9 @@ edit_mail_header_field_create(struct edit_mail *edmail, const char *field_name,
+ 					      &field->body_offset);
+ 
+ 		/* Copy to new field */
+-		field->data = i_strndup(str_data(data), str_len(data));
+ 		field->size = str_len(data);
++		field->data = i_malloc(field->size + 1);
++		memcpy(field->data, str_data(data), field->size);
+ 		field->virtual_size = (edmail->crlf ?
+ 				       field->size : field->size + lines);
+ 		field->lines = lines;
+@@ -828,8 +829,9 @@ static int edit_mail_headers_parse(struct edit_mail *edmail)
+ 
+ 			field->size = str_len(hdr_data);
+ 			field->virtual_size = field->size + vsize_diff;
+-			field->data = i_strndup(str_data(hdr_data),
+-						field->size);
++			field->data = i_malloc(field->size + 1);
++			memcpy(field->data, str_data(hdr_data),
++			       field->size);
+ 			field->offset = offset;
+ 			field->lines = lines;
+ 
+@@ -887,7 +889,17 @@ static int edit_mail_headers_parse(struct edit_mail *edmail)
+ 		}
+ 	}
+ 
+-	/* Rebuild header index */
++	/* Rebuild header index. Reset first pointers before rebuilding so that
++	   the actual first occurrence in the final list is used. Without this,
++	   a snapshot's pre-set first pointer may refer to an appended field
++	   that sits later in the list than a parsed field with the same header,
++	   causing deleteheader to miss the parsed fields while still freeing
++	   the header_index — leaving stale field_idx->header pointers. */
++	struct _header_index *hidx = edmail->headers_head;
++	while (hidx != NULL) {
++		hidx->first = NULL;
++		hidx = hidx->next;
++	}
+ 	current = edmail->header_fields_head;
+ 	while (current != NULL) {
+ 		if (current->header->first == NULL)
+--- a/src/lib-sieve/util/test-edit-mail.c
++++ b/src/lib-sieve/util/test-edit-mail.c
+@@ -809,12 +809,91 @@ static void test_edit_mail_small_buffer(void)
+ 	test_end();
+ }
+ 
++static void test_edit_mail_nul_in_header(void)
++{
++	/* Message with a NUL byte embedded in the X-Has-NUL header value.
++	 * sizeof() - 1 gives the true byte count, skipping the C string's
++	 * trailing NUL terminator, while preserving the embedded \x00. */
++	static const unsigned char message[] =
++		"From: sender at example.com\n"
++		"X-Has-NUL: value\x00" "afterNUL\n"
++		"Subject: Test\n"
++		"\n"
++		"Body\n";
++	/* Expected output after deleting the Subject header. */
++	static const unsigned char expected[] =
++		"From: sender at example.com\n"
++		"X-Has-NUL: value\x00" "afterNUL\n"
++		"\n"
++		"Body\n";
++	struct istream *input_msg, *input_mail;
++	buffer_t *buffer;
++	struct mail_raw *rawmail;
++	struct edit_mail *edmail;
++	struct mail *mail;
++
++	test_begin("edit-mail - NUL byte in header value");
++	test_init();
++
++	/* sizeof - 1 excludes the trailing C-string NUL terminator */
++	input_msg = i_stream_create_from_data(message, sizeof(message) - 1);
++
++	rawmail = mail_raw_open_stream(test_raw_mail_user, input_msg);
++	edmail = edit_mail_wrap(rawmail->mail);
++
++	/* Deleting any header triggers edit_mail_headers_parse(), which with
++	 * the old i_strndup() allocated only strlen("X-Has-NUL: value")+1=17
++	 * bytes for X-Has-NUL's field->data even though field->size=26.
++	 * Streaming then called memcpy(dst, field->data, 26), reading 9 bytes
++	 * past the end of the allocation and producing garbage in place of
++	 * "afterNUL\n". */
++	edit_mail_header_delete(edmail, "Subject", 0);
++
++	mail = edit_mail_get_mail(edmail);
++
++	if (mail_get_stream(mail, NULL, NULL, &input_mail) < 0) {
++		i_fatal("Failed to open mail stream: %s",
++			mailbox_get_last_internal_error(mail->box, NULL));
++	}
++
++	buffer = buffer_create_dynamic(default_pool, 128);
++
++	/* normal */
++
++	i_stream_seek(input_mail, 0);
++	test_stream_data(input_mail, buffer);
++
++	test_out("nul in header",
++		 buffer->used == sizeof(expected) - 1 &&
++		 memcmp(buffer->data, expected, sizeof(expected) - 1) == 0);
++
++	/* slow (byte-by-byte) */
++
++	i_stream_seek(input_mail, 0);
++	buffer_set_used_size(buffer, 0);
++	test_stream_data_slow(input_mail, buffer);
++
++	test_out("nul in header, slow",
++		 buffer->used == sizeof(expected) - 1 &&
++		 memcmp(buffer->data, expected, sizeof(expected) - 1) == 0);
++
++	/* clean up */
++
++	buffer_free(&buffer);
++	edit_mail_unwrap(&edmail);
++	mail_raw_close(&rawmail);
++	i_stream_unref(&input_msg);
++	test_deinit();
++	test_end();
++}
++
+ int main(int argc, char *argv[])
+ {
+ 	static void (*test_functions[])(void) = {
+ 		test_edit_mail_concatenated,
+ 		test_edit_mail_big_header,
+ 		test_edit_mail_small_buffer,
++		test_edit_mail_nul_in_header,
+ 		NULL
+ 	};
+ 	const enum master_service_flags service_flags =
+new file mode 100644
+--- /dev/null
++++ b/tests/extensions/editheader/deleteheader-snapshot.svtest
+@@ -0,0 +1,76 @@
++require "vnd.dovecot.testsuite";
++require "editheader";
++require "fileinto";
++require "mailbox";
++
++/*
++ * Regression test: heap use-after-free in edit_mail_snapshot when
++ * deleteheader is called after a fileinto snapshot on an edit_mail
++ * whose headers have not yet been parsed.
++ */
++
++test_set "message" text:
++From: sender at example.com
++To: recipient at example.com
++Cc: original at example.com
++Subject: Test
++
++Body.
++.
++;
++
++test "deleteheader all: snapshot stale first pointer after parse" {
++	/* Add a Cc header while headers are not yet parsed.  The snapshot
++	 * created by the next fileinto has H_clone_cc->first pointing at
++	 * this appended field. */
++	addheader :last "Cc" "appended at example.com";
++
++	/* fileinto sets edit_snapshot=TRUE.  The next call to
++	 * sieve_message_edit creates a snapshot (edmail_snap) and the
++	 * fileinto action retains the pre-snapshot version for delivery. */
++	fileinto :create "folder1";
++
++	/* sieve_message_edit creates edmail_snap here.  edit_mail_headers_parse
++	 * inserts the parsed "Cc: original at example.com" before the appended
++	 * field in the list.  Without the fix the rebuild skips resetting
++	 * ->first; the delete loop then only removes the appended field,
++	 * frees H_clone_cc (index==0), and leaves the parsed field_idx with
++	 * a dangling ->header pointer. */
++	deleteheader "Cc";
++
++	/* A second fileinto + edit operation takes another snapshot of the
++	 * same edmail_snap.  edit_mail_snapshot walks header_fields_head and
++	 * reads field_idx->header->header on the orphaned entry.
++	 * Without the fix: use-after-free crash.
++	 * With the fix: clean run, both Cc occurrences are correctly gone. */
++	fileinto :create "folder2";
++	deleteheader "Subject";
++
++	if not test_result_execute {
++		test_fail "failed to execute result";
++	}
++
++	/* folder1 was snapshotted before deleteheader "Cc": both Cc headers
++	 * must be present. */
++	if not test_message :folder "folder1" 0 {
++		test_fail "message not stored in folder1";
++	}
++
++	if not header :is "Cc" "original at example.com" {
++		test_fail "original Cc missing in folder1 snapshot";
++	}
++
++	if not header :is "Cc" "appended at example.com" {
++		test_fail "appended Cc missing in folder1 snapshot";
++	}
++
++	/* folder2 was snapshotted after deleteheader "Cc": both Cc headers
++	 * must be absent. */
++	if not test_message :folder "folder2" 0 {
++		test_fail "message not stored in folder2";
++	}
++
++	if exists "Cc" {
++		test_fail "Cc header not fully deleted in folder2 snapshot";
++	}
++}
+new file mode 100644
+--- /dev/null
++++ b/tests/extensions/editheader/nul-value.svtest
+@@ -0,0 +1,46 @@
++require "vnd.dovecot.testsuite";
++require "encoded-character";
++require "variables";
++require "fileinto";
++require "mailbox";
++
++require "editheader";
++
++/*
++ * Regression test: edit_mail_headers_parse() used i_strndup() to copy the
++ * raw header data, which stopped at the first NUL byte and allocated a buffer
++ * shorter than field->size.  When the modified message was subsequently
++ * streamed (e.g. fileinto), memcpy() read field->size bytes out of that
++ * under-sized buffer, causing an invalid heap read detectable by valgrind.
++ */
++
++/* Construct a raw message that has a NUL byte inside a header value.
++ * ${hex:00} = NUL.  field->size covers the full header line including
++ * bytes after the NUL; the old i_strndup() only allocated up to the NUL. */
++test_set "message" text:
++From: sender at example.com
++X-Has-NUL: value${hex:00}afterNUL
++Subject: Test
++
++Body
++.
++;
++
++test "editheader - NUL byte in header value" {
++	/* deleteheader calls edit_mail_headers_parse(), which allocates
++	 * field->data for every header including X-Has-NUL.  With the old
++	 * i_strndup() code, X-Has-NUL's allocation is only strlen("value")+1
++	 * bytes, but field->size covers the full extent including bytes after
++	 * the NUL.  deleteheader also sets modified=TRUE. */
++	deleteheader "Subject";
++
++	fileinto :create "nul-test";
++
++	/* Streaming iterates over all remaining parsed headers including
++	 * X-Has-NUL, reading field->size bytes from field->data.  With the
++	 * old under-sized allocation this is an invalid heap read that
++	 * valgrind detects. */
++	if not test_result_execute {
++		test_fail "failed to execute result";
++	}
++}
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/dovecot-pigeonhole.git/commitdiff/554c2b3c6d0c10ebecd3fa65868ed0eca334fdd7



More information about the pld-cvs-commit mailing list