Fix memory leak on bad inputs.
[openssl.git] / crypto / asn1 / x_name.c
index b46434c7bd32edf3b725334d1572333b7fdfb276..49be08b4daab7d43ba4ccaebd5f164e261264cd9 100644 (file)
@@ -64,7 +64,7 @@
 #include "asn1_locl.h"
 
 typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY;
-DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY);
+DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY)
 
 static int x509_name_ex_d2i(ASN1_VALUE **val,
                                const unsigned char **in, long len,
@@ -214,7 +214,9 @@ static int x509_name_ex_d2i(ASN1_VALUE **val,
        *val = nm.a;
        *in = p;
        return ret;
-       err:
+err:
+        if (nm.x != NULL)
+               X509_NAME_free(nm.x);
        ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
        return 0;
 }
@@ -400,6 +402,7 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
                out->type = in->type;
                if (!ASN1_STRING_set(out, in->data, in->length))
                        return 0;
+               return 1;
                }
 
        out->type = V_ASN1_UTF8STRING;
@@ -463,7 +466,8 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
                        }
                else
                        {
-                       *to++ = tolower(*from++);
+                       *to++ = tolower(*from);
+                       from++;
                        i++;
                        }
                }