]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix more issues in libmime
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 18 Sep 2021 11:56:46 +0000 (12:56 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 18 Sep 2021 11:56:46 +0000 (12:56 +0100)
Found by: coverity scan

src/libmime/archives.c
src/libmime/mime_encoding.c
src/libmime/mime_parser.c

index 1101213d19d05013cdd1ee13cbb229bfe976a8ca..467f9c021c8ea8292f183b7174e75a5c7e4fabe6 100644 (file)
@@ -141,7 +141,7 @@ rspamd_archive_process_zip (struct rspamd_task *task,
        guint32 cd_offset, cd_size, comp_size, uncomp_size, processed = 0;
        guint16 extra_len, fname_len, comment_len;
        struct rspamd_archive *arch;
-       struct rspamd_archive_file *f;
+       struct rspamd_archive_file *f = NULL;
 
        /* Zip files have interesting data at the end of archive */
        p = part->parsed_data.begin + part->parsed_data.len - 1;
@@ -1263,6 +1263,7 @@ rspamd_7zip_read_substreams_info (struct rspamd_task *task,
        }
 
        folder_nstreams = g_alloca (sizeof (guint64) * num_folders);
+       memset (folder_nstreams, 0, sizeof (guint64) * num_folders);
 
        while (p != NULL && p < end) {
                /*
@@ -1410,9 +1411,10 @@ rspamd_7zip_read_archive_props (struct rspamd_task *task,
         */
 
        proptype = *p;
-       SZ_SKIP_BYTES(1);
 
        if (p != NULL) {
+               SZ_SKIP_BYTES(1);
+
                while (proptype != 0) {
                        SZ_READ_VINT(proplen);
 
index edbee1a307d4d7341d5885f2e9d660a2f78d96aa..a3467fc914a5872c98f830090661d6264202ebbf 100644 (file)
@@ -638,14 +638,14 @@ rspamd_mime_charset_find_by_content_maybe_split (const gchar *in, gsize inlen)
                                RSPAMD_CHARSET_MAX_CONTENT, false);
 
                /* 7bit stuff */
-               if (strcmp (c1, "US-ASCII") == 0) {
+               if (c1 && strcmp (c1, "US-ASCII") == 0) {
                        c1 = NULL; /* Invalid - we have 8 bit there */
                }
-               if (strcmp (c2, "US-ASCII") == 0) {
+               if (c2 && strcmp (c2, "US-ASCII") == 0) {
                        c2 = NULL; /* Invalid - we have 8 bit there */
                }
-               if (strcmp (c3, "US-ASCII") == 0) {
-                       c2 = NULL; /* Invalid - we have 8 bit there */
+               if (c3 && strcmp (c3, "US-ASCII") == 0) {
+                       c3 = NULL; /* Invalid - we have 8 bit there */
                }
 
                if (!c1) {
index 0363d45140f9deea3a4445779c7e769aada9241b..6ec28e05727067b1bfd7ada9b82ad05c6d344d54 100644 (file)
@@ -596,14 +596,14 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
        g_assert (part != NULL);
 
        rspamd_mime_part_get_cte (task, part->raw_headers, part,
-                       !(part->ct->flags & RSPAMD_CONTENT_TYPE_MESSAGE));
+                       part->ct && !(part->ct->flags & RSPAMD_CONTENT_TYPE_MESSAGE));
        rspamd_mime_part_get_cd (task, part);
 
        switch (part->cte) {
        case RSPAMD_CTE_7BIT:
        case RSPAMD_CTE_8BIT:
        case RSPAMD_CTE_UNKNOWN:
-               if (part->ct->flags & RSPAMD_CONTENT_TYPE_MISSING) {
+               if (part->ct && (part->ct->flags & RSPAMD_CONTENT_TYPE_MISSING)) {
                        if (part->cte != RSPAMD_CTE_7BIT) {
                                /* We have something that has a missing content-type,
                                 * but it has non-7bit characters.
@@ -658,7 +658,9 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
                }
                else {
                        msg_err_task ("invalid quoted-printable encoded part, assume 8bit");
-                       part->ct->flags |= RSPAMD_CONTENT_TYPE_BROKEN;
+                       if (part->ct) {
+                               part->ct->flags |= RSPAMD_CONTENT_TYPE_BROKEN;
+                       }
                        part->cte = RSPAMD_CTE_8BIT;
                        memcpy (parsed->str, part->raw_data.begin, part->raw_data.len);
                        parsed->len = part->raw_data.len;
@@ -694,7 +696,9 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
                }
                else {
                        msg_err_task ("invalid uuencoding in encoded part, assume 8bit");
-                       part->ct->flags |= RSPAMD_CONTENT_TYPE_BROKEN;
+                       if (part->ct) {
+                               part->ct->flags |= RSPAMD_CONTENT_TYPE_BROKEN;
+                       }
                        part->cte = RSPAMD_CTE_8BIT;
                        parsed->len = MIN (part->raw_data.len, parsed->allocated);
                        memcpy (parsed->str, part->raw_data.begin, parsed->len);