[dovecot] Patch for zero content-length

Tim Hunt timhunt at users.sf.net
Mon Apr 21 04:25:39 EEST 2003


mbox-index.c uses a zero content length as a flag for an invalid 
Content-Length: header. Unfortunately zero is also a valid value for 
Content-Length. The patch below attempts to address the problem.


*** mbox-index.h.orig   Tue Apr 15 09:04:02 2003
--- mbox-index.h        Sun Apr 20 11:42:12 2003
***************
*** 19,24 ****
--- 19,25 ----
         struct istream *input;
         uoff_t content_length;
         int set_read_limit;
+       unsigned int content_length_good:1;
   };

   int mbox_set_syscall_error(struct mail_index *index, const char 
*function);

*** mbox-index.c.orig   Mon Mar 24 05:52:44 2003
--- mbox-index.c        Sun Apr 20 12:41:16 2003
***************
*** 264,277 ****
                 start_offset = ctx->input->v_offset;
                 i_stream_set_read_limit(ctx->input, 0);

!               end_offset = start_offset + ctx->content_length;
!               if (ctx->content_length == 0 ||
                     !mbox_verify_end_of_body(ctx->input, end_offset)) {
!                       if (ctx->content_length != 0)
                                 i_stream_seek(ctx->input, start_offset);
                         mbox_skip_message(ctx->input);
                         end_offset = ctx->input->v_offset;
                         ctx->content_length = end_offset - start_offset;
                 }

                 i_stream_seek(ctx->input, start_offset);
--- 264,280 ----
                 start_offset = ctx->input->v_offset;
                 i_stream_set_read_limit(ctx->input, 0);

!               end_offset = start_offset;
!               if ( ctx->content_length_good )
!                       end_offset += ctx->content_length;
!               if (!ctx->content_length_good ||
                     !mbox_verify_end_of_body(ctx->input, end_offset)) {
!                       if (ctx->content_length_good )
                                 i_stream_seek(ctx->input, start_offset);
                         mbox_skip_message(ctx->input);
                         end_offset = ctx->input->v_offset;
                         ctx->content_length = end_offset - start_offset;
+                       ctx->content_length_good = TRUE;
                 }

                 i_stream_seek(ctx->input, start_offset);
***************
*** 301,311 ****
--- 304,316 ----
                     strcasecmp(hdr->name, "Content-Length") == 0) {
                         /* manual parsing, so we can deal with uoff_t */
                         ctx->content_length = 0;
+                       ctx->content_length_good = TRUE;
                         for (i = 0; i < hdr->value_len; i++) {
                                 if (hdr->value[i] < '0' ||
                                     hdr->value[i] > '9') {
                                         /* invalid */
                                         ctx->content_length = 0;
+                                       ctx->content_length_good = FALSE;
                                         break;
                                 }





More information about the dovecot mailing list