Put file-creating fopen() calls in content-scanning code in a wrapper
[exim.git] / src / src / mime.c
index a4ad0f50904bd3a7862101db54b013afd20eebcb..c215b7bcf159d430f6f631a34a2b6fb2a4ab92a2 100644 (file)
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/src/src/mime.c,v 1.9 2005/07/01 10:49:02 ph10 Exp $ */
+/* $Cambridge: exim/src/src/mime.c,v 1.14 2006/02/22 14:46:44 ph10 Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
@@ -159,7 +159,6 @@ uschar *mime_parse_line(uschar *buffer, uschar *data, uschar *encoding, int *num
 
       /* byte 0 ---------------------- */
       if (*(p+1) == 255) {
-        mime_set_anomaly(MIME_ANOMALY_BROKEN_BASE64);
         break;
       }
       data[(*num_decoded)] = *p;
@@ -171,7 +170,6 @@ uschar *mime_parse_line(uschar *buffer, uschar *data, uschar *encoding, int *num
       p++;
       /* byte 1 ---------------------- */
       if (*(p+1) == 255) {
-        mime_set_anomaly(MIME_ANOMALY_BROKEN_BASE64);
         break;
       }
       data[(*num_decoded)] = *p;
@@ -183,7 +181,6 @@ uschar *mime_parse_line(uschar *buffer, uschar *data, uschar *encoding, int *num
       p++;
       /* byte 2 ---------------------- */
       if (*(p+1) == 255) {
-        mime_set_anomaly(MIME_ANOMALY_BROKEN_BASE64);
         break;
       }
       data[(*num_decoded)] = *p;
@@ -243,11 +240,11 @@ FILE *mime_get_decode_file(uschar *pname, uschar *fname) {
   filename = (uschar *)malloc(2048);
 
   if ((pname != NULL) && (fname != NULL)) {
-    snprintf(CS filename, 2048, "%s/%s", pname, fname);
-    f = fopen(CS filename,"wb+");
+    (void)string_format(filename, 2048, "%s/%s", pname, fname);
+    f = modefopen(filename,"wb+",SPOOL_MODE);
   }
   else if (pname == NULL) {
-    f = fopen(CS fname,"wb+");
+    f = modefopen(fname,"wb+",SPOOL_MODE);
   }
   else if (fname == NULL) {
     int file_nr = 0;
@@ -256,7 +253,7 @@ FILE *mime_get_decode_file(uschar *pname, uschar *fname) {
     /* must find first free sequential filename */
     do {
       struct stat mystat;
-      snprintf(CS filename,2048,"%s/%s-%05u", pname, message_id, file_nr);
+      (void)string_format(filename,2048,"%s/%s-%05u", pname, message_id, file_nr);
       file_nr++;
       /* security break */
       if (file_nr >= 1024)
@@ -264,7 +261,7 @@ FILE *mime_get_decode_file(uschar *pname, uschar *fname) {
       result = stat(CS filename,&mystat);
     }
     while(result != -1);
-    f = fopen(CS filename,"wb+");
+    f = modefopen(filename,"wb+",SPOOL_MODE);
   };
 
   /* set expansion variable */
@@ -292,7 +289,7 @@ int mime_decode(uschar **listptr) {
   f_pos = ftell(mime_stream);
 
   /* build default decode path (will exist since MBOX must be spooled up) */
-  snprintf(CS decode_path,1024,"%s/scan/%s",spool_directory,message_id);
+  (void)string_format(decode_path,1024,"%s/scan/%s",spool_directory,message_id);
 
   /* reserve a line and decoder buffer to work in */
   buffer = (uschar *)malloc(MIME_MAX_LINE_LENGTH+1);
@@ -487,7 +484,7 @@ int mime_get_header(FILE *f, uschar *header) {
     };
   };
 
-  if (header[num_copied-1] != ';') {
+  if ((num_copied > 0) && (header[num_copied-1] != ';')) {
     header[num_copied-1] = ';';
   };
 
@@ -622,7 +619,7 @@ int mime_acl_check(uschar *acl, FILE *f, struct mime_boundary_context *context,
                 memset(param_value,0,param_value_len+1);
                 q = p + mime_parameter_list[j].namelen;
                 Ustrncpy(param_value, q, param_value_len);
-                param_value = rfc2047_decode(param_value, TRUE, NULL, 32, &param_value_len, &q);
+                param_value = rfc2047_decode(param_value, check_rfc2047_length, NULL, 32, &param_value_len, &q);
                 debug_printf("Found %s MIME parameter in %s header, value is '%s'\n", mime_parameter_list[j].name, mime_header_list[i].name, param_value);
                 *((uschar **)(mime_parameter_list[j].value)) = param_value;
                 p += (mime_parameter_list[j].namelen + param_value_len + 1);
@@ -693,7 +690,7 @@ int mime_acl_check(uschar *acl, FILE *f, struct mime_boundary_context *context,
       /* must find first free sequential filename */
       do {
         struct stat mystat;
-        snprintf(CS filename,2048,"%s/scan/%s/__rfc822_%05u", spool_directory, message_id, file_nr);
+        (void)string_format(filename,2048,"%s/scan/%s/__rfc822_%05u", spool_directory, message_id, file_nr);
         file_nr++;
         /* security break */
         if (file_nr >= 128)