tDon't segfault if there is some empty Content-Type. - rohrpost - A commandline mail client to change the world as we see it.
 (HTM) git clone git://r-36.net/rohrpost
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit d59a3b539769e9b3f85a1a919b1853a7437ca0bc
 (DIR) parent 3cf0b9aa7ea814a2e50246c2a3ef91d842d94505
 (HTM) Author: Christoph Lohmann <20h@r-36.net>
       Date:   Tue, 15 Dec 2015 19:52:51 +0100
       
       Don't segfault if there is some empty Content-Type.
       
       Diffstat:
         mime.c                              |      44 ++++++++++++++++++-------------
       
       1 file changed, 26 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git a/mime.c b/mime.c
       t@@ -801,34 +801,41 @@ mime_preparepart(mime_t *mime)
                llist_t *hdrf;
        
                hdr = llist_ciget(mime->hdrs, "content-type");
       -        if (hdr != NULL && hdr->data != NULL) {
       +        if (hdr != NULL && hdr->data != NULL && strlen(hdr->data) > 0) {
                        //printf("content-type: %s\n", (char *)hdr->data);
                        hdrf = mime_parseheader(hdr->data);
                        //printf("%s\n", hdrf->first->key);
       -                if (!strncasecmp(hdrf->first->key, "multipart", 9)) {
       -                        //printf("is multipart\n");
       -                        field = llist_ciget(hdrf, "boundary");
       -                        if (field == NULL) {
       -                                return NULL;
       -                                //die("Could not find boundary "
       -                                //        "in multipart!\n");
       +                if (hdrf != NULL) {
       +                        if (!strncasecmp(hdrf->first->key, "multipart", 9)) {
       +                                //printf("is multipart\n");
       +                                field = llist_ciget(hdrf, "boundary");
       +                                if (field == NULL) {
       +                                        return NULL;
       +                                        //die("Could not find boundary "
       +                                        //        "in multipart!\n");
       +                                }
       +                                mime->boundary = smprintf("--%s",
       +                                                (char *)field->data);
       +                                //printf("boundary: \"%s\"\n", mime->boundary);
                                }
       -                        mime->boundary = smprintf("--%s", (char *)field->data);
       -                        //printf("boundary: \"%s\"\n", mime->boundary);
       -                }
       -                mime->ct = memdups(hdrf->first->key);
       +                        mime->ct = memdups(hdrf->first->key);
        
       -                field = llist_ciget(hdrf, "charset");
       -                if (field != NULL && field->data != NULL)
       -                        mime->charset = memdupz(field->data, field->datalen);
       +                        field = llist_ciget(hdrf, "charset");
       +                        if (field != NULL && field->data != NULL) {
       +                                mime->charset = memdupz(field->data,
       +                                                field->datalen);
       +                        }
        
       -                llist_free(hdrf);
       +                        llist_free(hdrf);
       +                }
                }
        
                if (mime->ct == NULL)
                        mime->ct = memdupz("text/plain", 10);
       +        //printf("mime->ct = %s\n", mime->ct);
                if (mime->charset == NULL)
                        mime->charset = memdupz("iso8859-1", 9);
       +        //printf("mime->charset = %s\n", mime->charset);
        
                hdr = llist_ciget(mime->hdrs, "Content-Transfer-Encoding");
                if (hdr != NULL && hdr->data != NULL) {
       t@@ -836,6 +843,7 @@ mime_preparepart(mime_t *mime)
                } else {
                        mime->cte = memdupz("7bit", 4);
                }
       +        //printf("mime->cte = %s\n", mime->cte);
        
                return mime;
        }
       t@@ -1278,8 +1286,8 @@ mime_filename(mime_t *mime)
                                        filename = mime_guessheader(
                                                        (char *)name->data);
                                }
       +                        llist_free(hdrp);
                        }
       -                llist_free(hdrp);
        
                        if (filename != NULL)
                                return filename;
       t@@ -1297,8 +1305,8 @@ mime_filename(mime_t *mime)
                                        filename = mime_guessheader(
                                                        (char *)name->data);
                                }
       +                        llist_free(hdrp);
                        }
       -                llist_free(hdrp);
        
                        if (filename != NULL)
                                return filename;