Check for FindNextFile when defining it rather than FindFirstFile
[oweals/openssl.git] / crypto / asn1 / a_strex.c
index 7fc14d3296c1ccb1db5b433b5c316375c265bfcc..8fb4193bc0b299b9a73a294b3dde7b150a012bcd 100644 (file)
 
 #define CHARTYPE_BS_ESC                (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253)
 
+#define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \
+                 ASN1_STRFLGS_ESC_QUOTE | \
+                 ASN1_STRFLGS_ESC_CTRL | \
+                 ASN1_STRFLGS_ESC_MSB)
+
 
 /* Three IO functions for sending data to memory, a BIO and
  * and a FILE pointer.
@@ -148,6 +153,13 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, ch
                if(!io_ch(arg, tmphex, 3)) return -1;
                return 3;
        }
+       /* If we get this far and do any escaping at all must escape 
+        * the escape character itself: backslash.
+        */
+       if (chtmp == '\\' && flags & ESC_FLAGS) {
+               if(!io_ch(arg, "\\\\", 2)) return -1;
+               return 2;
+       }
        if(!io_ch(arg, &chtmp, 1)) return -1;
        return 1;
 }
@@ -292,11 +304,6 @@ static const signed char tag2nbyte[] = {
        4, -1, 2                /* 28-30 */
 };
 
-#define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \
-                 ASN1_STRFLGS_ESC_QUOTE | \
-                 ASN1_STRFLGS_ESC_CTRL | \
-                 ASN1_STRFLGS_ESC_MSB)
-
 /* This is the main function, print out an
  * ASN1_STRING taking note of various escape
  * and display options. Returns number of
@@ -560,6 +567,8 @@ int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
        if(mbflag == -1) return -1;
        mbflag |= MBSTRING_FLAG;
        stmp.data = NULL;
+       stmp.length = 0;
+       stmp.flags = 0;
        ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
        if(ret < 0) return ret;
        *out = stmp.data;