httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From max...@apache.org
Subject svn commit: r356322 - in /httpd/mod_mbox/trunk/module-2.0: mod_mbox.h mod_mbox_file.c mod_mbox_mime.c mod_mbox_out.c
Date Mon, 12 Dec 2005 18:51:33 GMT
Author: maxime
Date: Mon Dec 12 10:51:27 2005
New Revision: 356322

URL: http://svn.apache.org/viewcvs?rev=356322&view=rev
Log:
Handle badly parsed messages : in some unknown cases, mod-mbox-util
issues weird numbers for message/body start and end offsets.

  * module-2.0/mod_mbox_file.c
     (fetch_message): Make fetch_message return NULL when message
length is wrong.

  * module-2.0/mod_mbox.h
     Add a default error string.

  * module-2.0/mod_mbox_mime.c
     (mbox_mime_decode_multipart): directly return NULL when facing a
NULL message body. Fix some identation errors.

  * module-2.0/mod_mbox_out.c
     (mbox_raw_message): display our error string instead of trying to
display a NULL string.



Modified:
    httpd/mod_mbox/trunk/module-2.0/mod_mbox.h
    httpd/mod_mbox/trunk/module-2.0/mod_mbox_file.c
    httpd/mod_mbox/trunk/module-2.0/mod_mbox_mime.c
    httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox.h
URL: http://svn.apache.org/viewcvs/httpd/mod_mbox/trunk/module-2.0/mod_mbox.h?rev=356322&r1=356321&r2=356322&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox.h (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox.h Mon Dec 12 10:51:27 2005
@@ -65,6 +65,8 @@
 
 #define MBOX_ATOM_NUM_ENTRIES 40
 
+#define MBOX_FETCH_ERROR_STR "An error occured while fetching this message, sorry !"
+
 typedef struct mbox_dir_cfg {
     int enabled;
     int antispam;

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox_file.c
URL: http://svn.apache.org/viewcvs/httpd/mod_mbox/trunk/module-2.0/mod_mbox_file.c?rev=356322&r1=356321&r2=356322&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox_file.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox_file.c Mon Dec 12 10:51:27 2005
@@ -37,6 +37,16 @@
     }
 
     len = m->body_end - m->msg_start;
+
+    /* If message len is invalid or nul, return immediately with NULL
+       values */
+    if (!len) {
+        m->raw_msg = NULL;
+	m->raw_body = NULL;
+
+	return m;
+    }
+
     m->raw_msg = apr_palloc(r->pool, len+1);
 
     if (apr_file_read(f, m->raw_msg, &len) != APR_SUCCESS) {

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox_mime.c
URL: http://svn.apache.org/viewcvs/httpd/mod_mbox/trunk/module-2.0/mod_mbox_mime.c?rev=356322&r1=356321&r2=356322&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox_mime.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox_mime.c Mon Dec 12 10:51:27 2005
@@ -30,10 +30,14 @@
     char *tmp = NULL, *k = NULL, *end_bound = NULL;
     char *headers_bound = NULL;
 
+    if (!body) {
+        return NULL;
+    }
+
     /* Locate the end of part headers */
     headers_bound = ap_strstr(body, "\n\n");
     if (!headers_bound) {
-      return NULL;
+        return NULL;
     }
 
     /* If no Content-Type is provided, it means that we are parsing a
@@ -42,7 +46,7 @@
        text/plain as default for the sub-part. */
     tmp = ap_strstr(body, "Content-Type: ");
     if (!ct && (!tmp || tmp > headers_bound)) {
-      ct = "text/plain";
+        ct = "text/plain";
     }
 
     mail = apr_pcalloc(p, sizeof(mbox_mime_message_t));
@@ -97,8 +101,9 @@
 	    *k = ';';
 	}
     }
-    else
-      mail->content_type = ct;
+    else {
+        mail->content_type = ct;
+    }
 
     /* Now we have a Content-Type. Look for other useful header information */
 
@@ -146,7 +151,7 @@
 	  }
       }
     else {
-      mail->cte = cte;
+        mail->cte = cte;
     }
 
     /* Now we have all the headers we need. Start processing the
@@ -309,7 +314,7 @@
     /* If the message structure or the message body is empty, just
        return NULL */
     if (!m || !m->body) {
-        return NULL;
+        return MBOX_FETCH_ERROR_STR;
     }
 
     if (strncasecmp(m->content_type, "text/", strlen("text/")) == 0) {
@@ -317,7 +322,7 @@
 
 	new_body = mbox_mime_decode_body(p, m->cte, m->body, m->body_len);
 	if (!new_body) {
-	    return NULL;
+	    return MBOX_FETCH_ERROR_STR;
 	}
 
 	m->body_len = mbox_cte_escape_html(p, new_body, m->body_len, &(m->body));
@@ -326,14 +331,14 @@
     }
 
     if (!m->sub) {
-        return NULL;
+        return MBOX_FETCH_ERROR_STR;
     }
 
     for (i=0 ; i<m->sub_count ; i++) {
         return mbox_mime_get_body(p, m->sub[i]);
     }
 
-    return NULL;
+    return MBOX_FETCH_ERROR_STR;
 }
 
 /* Display an XHTML MIME structure */

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c
URL: http://svn.apache.org/viewcvs/httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c?rev=356322&r1=356321&r2=356322&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c Mon Dec 12 10:51:27 2005
@@ -41,12 +41,13 @@
     { "Dec", "December" }
 };
 
+/* Display an ATOM feed entry from given message structure */
 void display_atom_entry(request_rec *r, Message *m, const char* mboxfile,
                         apr_pool_t *pool, apr_file_t *f)
 {
     char dstr[100];
     apr_size_t dlen;
-    apr_time_exp_t extime; 
+    apr_time_exp_t extime;
     char* uid;
     char* c;
 
@@ -56,7 +57,7 @@
                ESCAPE_OR_BLANK(pool, m->from));
 
     ap_rprintf(r, "<link rel=\"alternate\" href=\"%s%s/%s\"/>\n",
-               ap_construct_url(r->pool, r->uri, r), 
+               ap_construct_url(r->pool, r->uri, r),
                mboxfile, URI_ESCAPE_OR_BLANK(pool, m->msgID));
 
     uid = URI_ESCAPE_OR_BLANK(pool, m->msgID);
@@ -103,7 +104,7 @@
     Message *m;
     int i;
     apr_pool_t* tpool;
-    
+
     apr_pool_create(&tpool, r->pool);
 
     filename = apr_pstrcat(r->pool, r->filename, mboxfile, NULL);
@@ -122,7 +123,7 @@
     r->filename = filename;
 
     head = mbox_load_index(r, f, NULL);
-    
+
     /* Sort the list */
     head = mbox_sort_list(head, MBOX_SORT_REVERSE_DATE);
 
@@ -204,7 +205,7 @@
 
     for (i = 0; i < files->nelts; i++) {
         if (fi[i].count || !conf->hide_empty) {
-	    ap_rprintf(r, "<mbox id=\"%s\" count=\"%d\" />\n", 
+	    ap_rprintf(r, "<mbox id=\"%s\" count=\"%d\" />\n",
                        fi[i].filename, fi[i].count);
 	}
     }
@@ -333,7 +334,7 @@
 
 	    ap_rputs("    <tr>\n", r);
 	    ap_rprintf(r, "     <td class=\"date\">%s %.4s</td>\n",
-		       mbox_months[atoi(apr_pstrndup(r->pool, 
+		       mbox_months[atoi(apr_pstrndup(r->pool,
                                                      fi[i].filename+4, 2)) - 1][0],
 		       fi[i].filename);
 	    ap_rprintf(r, "     <td class=\"links\"><span class=\"links\" id=\"%.4s%.2s\">"
@@ -349,7 +350,6 @@
 	}
 
 	/* Year separation */
-     
 	if ((fi[i+1].filename && year_hdr) &&
 	    (fi[i].filename[3] != fi[i+1].filename[3])) {
 	    ap_rputs("    </tbody>\n", r);
@@ -945,11 +945,17 @@
         return HTTP_NOT_FOUND;
     }
 
+    if (!m->raw_msg) {
+        ap_set_content_type(r, "text/plain");
+        ap_rprintf(r, "%s", MBOX_FETCH_ERROR_STR);
+    }
+
     /* No MIME part specified : output whole message and return. */
     if (!part) {
         ap_set_content_type(r, "text/plain");
 	ap_rprintf(r, "%s", m->raw_msg);
-	return OK;
+
+        return OK;
     }
 
     /* Empty MIME part : we want only mail's body */



Mime
View raw message