Change safestack reimplementation to match 0.9.8.
[openssl.git] / crypto / asn1 / asn1_lib.c
index 73fc4673319cd12c5b42cd5cd6511a7d7a9e14f0..1bcb44aee203637ec70a60fe616588696bac32ac 100644 (file)
@@ -340,20 +340,31 @@ int asn1_GetSequence(ASN1_const_CTX *c, long *length)
        return(1);
        }
 
+int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
+       {
+       if (str == NULL)
+               return 0;
+       dst->type = str->type;
+       if (!ASN1_STRING_set(dst,str->data,str->length))
+               return 0;
+       dst->flags = str->flags;
+       return 1;
+       }
+
 ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str)
        {
        ASN1_STRING *ret;
-
-       if (str == NULL) return(NULL);
-       if ((ret=ASN1_STRING_type_new(str->type)) == NULL)
-               return(NULL);
-       if (!ASN1_STRING_set(ret,str->data,str->length))
+       if (!str)
+                return NULL;
+       ret=ASN1_STRING_new();
+       if (!ret)
+               return NULL;
+       if (!ASN1_STRING_copy(ret,str))
                {
                ASN1_STRING_free(ret);
-               return(NULL);
+               return NULL;
                }
-       ret->flags = str->flags;
-       return(ret);
+       return ret;
        }
 
 int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
@@ -427,7 +438,8 @@ ASN1_STRING *ASN1_STRING_type_new(int type)
 void ASN1_STRING_free(ASN1_STRING *a)
        {
        if (a == NULL) return;
-       if (a->data != NULL) OPENSSL_free(a->data);
+       if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF))
+               OPENSSL_free(a->data);
        OPENSSL_free(a);
        }