From f3f141664cd17c6d9847069ae5a4f29531bd93bb Mon Sep 17 00:00:00 2001 From: Bron Gondwana Date: Thu, 29 Feb 2024 22:39:20 -0500 Subject: [PATCH] sync_support: duplicate the sieve script --- imap/sync_support.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/imap/sync_support.c b/imap/sync_support.c index bc6551f0b9..72ce291fab 100644 --- a/imap/sync_support.c +++ b/imap/sync_support.c @@ -1024,14 +1024,20 @@ static int sync_sieve_validate(struct index_record *record, sieve_script_t *s = NULL; char *err = NULL; - r = sieve_script_parse_string(NULL, - msg_base + body->header_size, &err, &s); + // XXX: if mmap is a multiple of 4096 bytes, we can read past the + // end of the mmap - the string won't be correctly NULL terminated + char *script = xstrndup(msg_base + body->header_size, msg_len - body->header_size); + r = sieve_script_parse_string(NULL, script, &err, &s); + free(script); sieve_script_free(&s); if (r == SIEVE_OK) { // create the record now to avoid a re-parse in sync_append_copyfile message_create_record(record, body); } + else if (err) { + syslog(LOG_ERR, "sieve script parse error uid=%u: %s", record->uid, err); + } } if (body) {