]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: Add asserts to message_part_*() to make sure part->data isn't NULL
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 25 Jul 2018 10:17:05 +0000 (13:17 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 25 Jul 2018 10:17:05 +0000 (13:17 +0300)
This makes it easier to debug the crashes than just having a segfault.

src/lib-mail/message-part-data.c

index 779d8107b5bfdcc0f2eae3be2bac1d31b617a9f5..ffae458f55af1427ffdd139fed54f4d1f22a2f8e 100644 (file)
@@ -25,6 +25,7 @@ bool message_part_data_is_plain_7bit(const struct message_part *part)
 {
        const struct message_part_data *data = part->data;
 
+       i_assert(data != NULL);
        i_assert(part->parent == NULL);
 
        /* if content-type is text/xxx we don't have to check any
@@ -73,6 +74,8 @@ bool message_part_data_get_filename(const struct message_part *part,
        const struct message_part_param *params;
        unsigned int params_count, i;
 
+       i_assert(data != NULL);
+
        params = data->content_disposition_params;
        params_count = data->content_disposition_params_count;
 
@@ -539,6 +542,8 @@ bool message_part_has_content_types(struct message_part *part,
        const char *const *ptr;
        const char *content_type;
 
+       i_assert(data != NULL);
+
        if (data->content_type == NULL)
                return FALSE;
        else if (data->content_subtype == NULL)
@@ -560,6 +565,8 @@ bool message_part_has_parameter(struct message_part *part, const char *parameter
 {
        struct message_part_data *data = part->data;
 
+       i_assert(data != NULL);
+
        for (unsigned int i = 0; i < data->content_disposition_params_count; i++) {
                const struct message_part_param *param =
                        &data->content_disposition_params[i];