local_scan: align local_scan.h and docs re. store_get()
[exim.git] / src / src / rfc2047.c
index 1a2e9c7583fbf97544a15edc188800e7e7361af8..f7085007a8df5ecf10b7fde81b4c8b86bc9124fd 100644 (file)
@@ -2,7 +2,7 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2015 */
+/* Copyright (c) University of Cambridge 1995 - 2018 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 /* This file contains a function for decoding message header lines that may
@@ -46,11 +46,11 @@ rfc2047_qpdecode(uschar *string, uschar **ptrptr)
 int len = 0;
 uschar *ptr;
 
-ptr = *ptrptr = store_get(Ustrlen(string) + 1);  /* No longer than this */
+ptr = *ptrptr = store_get(Ustrlen(string) + 1, is_tainted(string));  /* No longer than this */
 
 while (*string != 0)
   {
-  register int ch = *string++;
+  int ch = *string++;
 
   if (ch == '_') *ptr++ = ' ';
   else if (ch == '=')
@@ -188,18 +188,18 @@ uschar *
 rfc2047_decode2(uschar *string, BOOL lencheck, uschar *target, int zeroval,
   int *lenptr, int *sizeptr, uschar **error)
 {
-int ptr = 0;
 int size = Ustrlen(string);
 size_t dlen;
-uschar *dptr, *yield;
+uschar *dptr;
+gstring *yield;
 uschar *mimeword, *q1, *q2, *endword;
 
 *error = NULL;
 mimeword = decode_mimeword(string, lencheck, &q1, &q2, &endword, &dlen, &dptr);
 
-if (mimeword == NULL)
+if (!mimeword)
   {
-  if (lenptr != NULL) *lenptr = size;
+  if (lenptr) *lenptr = size;
   return string;
   }
 
@@ -208,9 +208,12 @@ building the result as we go. The result may be longer than the input if it is
 translated into a multibyte code such as UTF-8. That's why we use the dynamic
 string building code. */
 
-yield = store_get(++size);
+yield = store_get(sizeof(gstring) + ++size, is_tainted(string));
+yield->size = size;
+yield->ptr = 0;
+yield->s = US(yield + 1);
 
-while (mimeword != NULL)
+while (mimeword)
   {
 
   #if HAVE_ICONV
@@ -218,7 +221,8 @@ while (mimeword != NULL)
   #endif
 
   if (mimeword != string)
-    yield = string_cat(yield, &size, &ptr, string, mimeword - string);
+    yield = string_catn(yield, string, mimeword - string);
+/*XXX that might have to convert an untainted string to a tainted one */
 
   /* Do a charset translation if required. This is supported only on hosts
   that have the iconv() function. Translation errors set error, but carry on,
@@ -297,15 +301,12 @@ while (mimeword != NULL)
     /* Deal with zero values; convert them if requested. */
 
     if (zeroval != 0)
-      {
-      int i;
-      for (i = 0; i < tlen; i++)
+      for (int i = 0; i < tlen; i++)
         if (tptr[i] == 0) tptr[i] = zeroval;
-      }
 
     /* Add the new string onto the result */
 
-    yield = string_cat(yield, &size, &ptr, tptr, tlen);
+    yield = string_catn(yield, tptr, tlen);
     }
 
   #if HAVE_ICONV
@@ -317,7 +318,7 @@ while (mimeword != NULL)
 
   string = endword + 2;
   mimeword = decode_mimeword(string, lencheck, &q1, &q2, &endword, &dlen, &dptr);
-  if (mimeword != NULL)
+  if (mimeword)
     {
     uschar *s = string;
     while (isspace(*s)) s++;
@@ -328,11 +329,11 @@ while (mimeword != NULL)
 /* Copy the remaining characters of the string, zero-terminate it, and return
 the length as well if requested. */
 
-yield = string_cat(yield, &size, &ptr, string, Ustrlen(string));
-yield[ptr] = 0;
-if (lenptr != NULL) *lenptr = ptr;
-if (sizeptr != NULL) *sizeptr = size;
-return yield;
+yield = string_cat(yield, string);
+
+if (lenptr) *lenptr = yield->ptr;
+if (sizeptr) *sizeptr = yield->size;
+return string_from_gstring(yield);
 }