From 085cad822704eb7b6cc8d73f4f5b62cae8f37168 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Fri, 7 Aug 2009 22:36:04 +0200 Subject: [PATCH] Fixed segfault bug: made sure return_path is never used without checking for NULL first. --- src/lib-sieve/plugins/enotify/ntfy-mailto.c | 2 +- src/lib-sieve/plugins/notify/cmd-notify.c | 2 +- src/lib-sieve/sieve-address.c | 24 ++++++++++++++++----- src/sieve-tools/sieve-test.c | 3 +-- src/testsuite/testsuite-smtp.c | 3 ++- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/lib-sieve/plugins/enotify/ntfy-mailto.c b/src/lib-sieve/plugins/enotify/ntfy-mailto.c index 36ed896da..5ebd2ce59 100644 --- a/src/lib-sieve/plugins/enotify/ntfy-mailto.c +++ b/src/lib-sieve/plugins/enotify/ntfy-mailto.c @@ -934,7 +934,7 @@ static bool ntfy_mailto_send } /* Determine SMTP from address */ - if ( msgdata->return_path != NULL ) { + if ( msgdata->return_path != NULL && *(msgdata->return_path) != '\0' ) { if ( mtctx->from_normalized == NULL ) { from_smtp = senv->postmaster_address; } else { diff --git a/src/lib-sieve/plugins/notify/cmd-notify.c b/src/lib-sieve/plugins/notify/cmd-notify.c index fe9d175ec..6738df28c 100644 --- a/src/lib-sieve/plugins/notify/cmd-notify.c +++ b/src/lib-sieve/plugins/notify/cmd-notify.c @@ -863,7 +863,7 @@ static bool act_notify_send /* Send message to all recipients */ for ( i = 0; i < count; i++ ) { - if ( msgdata->return_path != NULL ) + if ( msgdata->return_path != NULL && *(msgdata->return_path) != '\0' ) smtp_handle = sieve_smtp_open (senv, recipients[i].normalized, senv->postmaster_address, &f); else diff --git a/src/lib-sieve/sieve-address.c b/src/lib-sieve/sieve-address.c index 1666180c9..d43070ce1 100644 --- a/src/lib-sieve/sieve-address.c +++ b/src/lib-sieve/sieve-address.c @@ -255,6 +255,11 @@ bool sieve_rfc2822_mailbox_validate(const char *address, const char **error_r) { struct sieve_message_address_parser ctx; + if ( address == NULL ) { + *error_r = "null address"; + return FALSE; + } + memset(&ctx, 0, sizeof(ctx)); ctx.local_part = t_str_new(128); @@ -276,10 +281,15 @@ bool sieve_rfc2822_mailbox_validate(const char *address, const char **error_r) } const char *sieve_rfc2822_mailbox_normalize - (const char *address, const char **error_r) +(const char *address, const char **error_r) { struct sieve_message_address_parser ctx; + if ( error_r != NULL ) + *error_r = NULL; + + if ( address == NULL ) return NULL; + memset(&ctx, 0, sizeof(ctx)); ctx.local_part = t_str_new(128); @@ -293,9 +303,6 @@ const char *sieve_rfc2822_mailbox_normalize *error_r = str_c(ctx.error); return NULL; } - - if ( error_r != NULL ) - *error_r = NULL; (void)str_lcase(str_c_modifiable(ctx.domain)); @@ -361,6 +368,9 @@ int sieve_address_compare /* FIXME: provided addresses are currently assumed to be normalized to * local_part@domain */ + + i_assert(address1 != NULL); + i_assert(address2 != NULL); return strcasecmp(address1, address2); } @@ -398,7 +408,7 @@ int sieve_address_compare static unsigned char rfc2821_chars[256] = { DB, DB, DB, DB, DB, DB, DB, DB, // 0 DB, QB, QB, DB, DB, QB, DB, DB, // 8 - DB, DB, DB, DB, DB, DB, DB, DB, // 16 + DB, DB, DB, DB, DB, DB, DB, DB, // 16 DB, DB, DB, DB, DB, DB, DB, DB, // 24 QB, DB|AB, QB|DB, DB|AB, DB|AB, DB|AB, DB|AB, DB|AB, // 32 DB, DB, DB|AB, DB|AB, DB, DB|AB, DB, DB|AB, // 40 @@ -748,6 +758,10 @@ const struct sieve_address *sieve_address_parse_envelope_path struct sieve_envelope_address_parser parser; int ret; + if ( field_value == NULL ) { + return t_new(struct sieve_address, 1); + } + parser.data = (const unsigned char *) field_value; parser.end = (const unsigned char *) field_value + strlen(field_value); parser.address = t_new(struct sieve_address, 1); diff --git a/src/sieve-tools/sieve-test.c b/src/sieve-tools/sieve-test.c index 689840373..e042c654e 100644 --- a/src/sieve-tools/sieve-test.c +++ b/src/sieve-tools/sieve-test.c @@ -61,8 +61,7 @@ static void *sieve_smtp_open const char *return_path, FILE **file_r) { i_info("sending message from <%s> to <%s>:", - return_path == NULL || *return_path == '\0' ? "" : return_path, - destination); + ( return_path == NULL ? "" : return_path ), destination); printf("\nSTART MESSAGE:\n"); *file_r = stdout; diff --git a/src/testsuite/testsuite-smtp.c b/src/testsuite/testsuite-smtp.c index 18eff1ca8..5308d3af2 100644 --- a/src/testsuite/testsuite-smtp.c +++ b/src/testsuite/testsuite-smtp.c @@ -81,7 +81,8 @@ void *testsuite_smtp_open smtp_msg.file = p_strdup_printf(testsuite_smtp_pool, "%s/%d.eml", testsuite_smtp_tmp, smtp_count); - smtp_msg.envelope_from = p_strdup(testsuite_smtp_pool, return_path); + smtp_msg.envelope_from = + ( return_path != NULL ? p_strdup(testsuite_smtp_pool, return_path) : NULL ); smtp_msg.envelope_to = p_strdup(testsuite_smtp_pool, destination); array_append(&testsuite_smtp_messages, &smtp_msg, 1); -- GitLab