[exim-cvs] Handle \n in tls_peerdn for spool files.

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Exim Git Commits Mailing List
Date:  
À: exim-cvs
Sujet: [exim-cvs] Handle \n in tls_peerdn for spool files.
Gitweb: http://git.exim.org/exim.git/commitdiff/c7396ac5dedeca5d791113782ae72b4bb67692e3
Commit:     c7396ac5dedeca5d791113782ae72b4bb67692e3
Parent:     9d0b48b5f71beceebee9f058224abd30952311ce
Author:     Phil Pennock <pdp@???>
AuthorDate: Fri Apr 27 02:39:59 2012 -0700
Committer:  Phil Pennock <pdp@???>
CommitDate: Fri Apr 27 02:39:59 2012 -0700


    Handle \n in tls_peerdn for spool files.


    Fixes bug 1240.
---
 src/src/functions.h |    1 +
 src/src/spool_in.c  |    2 +-
 src/src/spool_out.c |    2 +-
 src/src/string.c    |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+), 2 deletions(-)


diff --git a/src/src/functions.h b/src/src/functions.h
index 9e8a954..f1af42e 100644
--- a/src/src/functions.h
+++ b/src/src/functions.h
@@ -331,6 +331,7 @@ extern uschar *string_nextinlist(uschar **, int *, uschar *, int);
 extern uschar *string_open_failed(int, const char *, ...) PRINTF_FUNCTION(2,3);
 extern uschar *string_printing2(uschar *, BOOL);
 extern uschar *string_split_message(uschar *);
+extern uschar *string_unprinting(uschar *);
 extern BOOL    string_vformat(uschar *, int, const char *, va_list);
 extern int     strcmpic(const uschar *, const uschar *);
 extern int     strncmpic(const uschar *, const uschar *, int);
diff --git a/src/src/spool_in.c b/src/src/spool_in.c
index 0e4bc41..e0d7fcf 100644
--- a/src/src/spool_in.c
+++ b/src/src/spool_in.c
@@ -548,7 +548,7 @@ for (;;)
     else if (Ustrncmp(p, "ls_cipher", 9) == 0)
       tls_cipher = string_copy(big_buffer + 12);
     else if (Ustrncmp(p, "ls_peerdn", 9) == 0)
-      tls_peerdn = string_copy(big_buffer + 12);
+      tls_peerdn = string_unprinting(string_copy(big_buffer + 12));
     break;
     #endif


diff --git a/src/src/spool_out.c b/src/src/spool_out.c
index f84cda6..7b82299 100644
--- a/src/src/spool_out.c
+++ b/src/src/spool_out.c
@@ -228,7 +228,7 @@ if (bmi_verdicts != NULL) fprintf(f, "-bmi_verdicts %s\n", bmi_verdicts);
#ifdef SUPPORT_TLS
if (tls_certificate_verified) fprintf(f, "-tls_certificate_verified\n");
if (tls_cipher != NULL) fprintf(f, "-tls_cipher %s\n", tls_cipher);
-if (tls_peerdn != NULL) fprintf(f, "-tls_peerdn %s\n", tls_peerdn);
+if (tls_peerdn != NULL) fprintf(f, "-tls_peerdn %s\n", string_printing(tls_peerdn));
#endif

 /* To complete the envelope, write out the tree of non-recipients, followed by
diff --git a/src/src/string.c b/src/src/string.c
index 1c1f2dd..ece200b 100644
--- a/src/src/string.c
+++ b/src/src/string.c
@@ -242,9 +242,12 @@ if (isdigit(ch) && ch != '8' && ch != '9')
   }
 else switch(ch)
   {
+  case 'b':  ch = '\b'; break;
+  case 'f':  ch = '\f'; break;
   case 'n':  ch = '\n'; break;
   case 'r':  ch = '\r'; break;
   case 't':  ch = '\t'; break;
+  case 'v':  ch = '\v'; break;
   case 'x':
   ch = 0;
   if (isxdigit(p[1]))
@@ -329,6 +332,72 @@ while (*t != 0)
 *tt = 0;
 return ss;
 }
+
+/*************************************************
+*        Undo printing escapes in string         *
+*************************************************/
+
+/* This function is the reverse of string_printing2.  It searches for
+backslash characters and if any are found, it makes a new copy of the
+string with escape sequences parsed.  Otherwise it returns the original
+string.
+
+Arguments:
+  s             the input string
+
+Returns:        string with printing escapes parsed back
+*/
+
+uschar *
+string_unprinting(uschar *s)
+{
+uschar *p, *q, *r, *ss;
+int len, off;
+
+p = Ustrchr(s, '\\');
+if (!p) return s;
+
+len = Ustrlen(s) + 1;
+ss = store_get(len);
+
+q = ss;
+off = p - s;
+if (off)
+  {
+  memcpy(q, s, off);
+  q += off;
+  }
+
+while (*p)
+  {
+  if (*p == '\\')
+    {
+    *q = string_interpret_escape(&p);
+    }
+  else
+    {
+    r = Ustrchr(p, '\\');
+    if (!r)
+      {
+      off = Ustrlen(p);
+      memcpy(q, p, off);
+      p += off;
+      q += off;
+      break;
+      }
+    else
+      {
+      off = r - p;
+      memcpy(q, p, off);
+      q += off;
+      p = r;
+      }
+    }
+  }
+*q = '\0';
+
+return ss;
+}
 #endif  /* COMPILE_UTILITY */