subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bre...@apache.org
Subject svn commit: r1613683 - /subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c
Date Sat, 26 Jul 2014 17:01:01 GMT
Author: breser
Date: Sat Jul 26 17:01:00 2014
New Revision: 1613683

URL: http://svn.apache.org/r1613683
Log:
On svn-auth-x509 branch, Escape embedded NUL bytes in BMP, Universal and
  UTF-8 Strings.  We already did this for T61 and IA5 with fuzzy_escape.

* subversion/libsvn_subr:
  (nul_escape): New function.
  (x509name_to_utf8_string): Run resulting UTF-8 strings through nul_escape()

Modified:
    subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c

Modified: subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c?rev=1613683&r1=1613682&r2=1613683&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c (original)
+++ subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c Sat Jul 26 17:01:00
2014
@@ -706,6 +706,48 @@ fuzzy_escape(const svn_string_t *src, ap
   return svn_stringbuf__morph_into_string(outstr);
 }
 
+/* Escape only NUL characters from a string that is presumed to
+ * be UTF-8 encoded. */
+static const svn_string_t *
+nul_escape(const svn_string_t *src, apr_pool_t *result_pool)
+{
+  const char *end = src->data + src->len;
+  const char *p = src->data, *q;
+  svn_stringbuf_t *outstr;
+
+  for (q = p; q < end; q++)
+    {
+      if (*q == '\0')
+        break;
+    }
+
+  if (q == end)
+    return src;
+
+  outstr = svn_stringbuf_create_empty(result_pool);
+  while (1)
+    {
+      q = p;
+
+      /* Traverse till either unsafe character or eos. */
+      while (q < end && *q != '\0')
+        q++;
+
+      /* copy chunk before marker */
+      svn_stringbuf_appendbytes(outstr, p, q - p);
+
+      if (q == end)
+        break;
+
+      svn_stringbuf_appendcstr(outstr, "?\\000");
+
+      p = q + 1;
+    }
+
+  return svn_stringbuf__morph_into_string(outstr);
+}
+
+
 /* Convert an ISO-8859-1 (Latin-1) string to UTF-8.
    ISO-8859-1 is a strict subset of Unicode. */
 static svn_error_t *
@@ -750,7 +792,7 @@ x509name_to_utf8_string(const x509_name 
     {
     case ASN1_UTF8_STRING:
       if (svn_utf__is_valid(src_string->data, src_string->len))
-        return src_string;
+        return nul_escape(src_string, result_pool);
       else
         /* not a valid UTF-8 string, who knows what it is,
          * so run it through the fuzzy_escape code.  */
@@ -811,7 +853,7 @@ x509name_to_utf8_string(const x509_name 
       return fuzzy_escape(src_string, result_pool);
     }
 
-  return utf8_string;
+  return nul_escape(utf8_string, result_pool);
 }
 
 /*



Mime
View raw message