Memory leak and NULL dereference fixes.
[openssl.git] / crypto / asn1 / evp_asn1.c
index 3506005a7146faef41f681abfc70f273fe0cee00..1b9445973e49e803f57d2e927bff7a0b9f12704b 100644 (file)
@@ -66,7 +66,11 @@ int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
        ASN1_STRING *os;
 
        if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0);
-       if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0);
+       if (!M_ASN1_OCTET_STRING_set(os,data,len))
+               {
+               M_ASN1_OCTET_STRING_free(os);
+               return 0;
+               }
        ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os);
        return(1);
        }
@@ -115,7 +119,11 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data,
 
        if ((osp=ASN1_STRING_new()) == NULL) return(0);
        /* Grow the 'string' */
-       ASN1_STRING_set(osp,NULL,size);
+       if (!ASN1_STRING_set(osp,NULL,size))
+               {
+               ASN1_STRING_free(osp);
+               return(0);
+               }
 
        M_ASN1_STRING_length_set(osp, size);
        p=M_ASN1_STRING_data(osp);
@@ -137,9 +145,9 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
        int ret= -1,n;
        ASN1_INTEGER *ai=NULL;
        ASN1_OCTET_STRING *os=NULL;
-       unsigned char *p;
+       const unsigned char *p;
        long length;
-       ASN1_CTX c;
+       ASN1_const_CTX c;
 
        if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL))
                {