Constify d2i, s2i, c2i and r2i functions and other associated
[openssl.git] / crypto / asn1 / a_bitstr.c
index ed0bdfbde1a75ba478863bde12d351b4877ce6c7..c1d3c28210742e195564433b1ac77bce7bbaadb8 100644 (file)
@@ -113,13 +113,20 @@ int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
        return(ret);
        }
 
-ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
-            long len)
+ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
+       const unsigned char **pp, long len)
        {
        ASN1_BIT_STRING *ret=NULL;
-       unsigned char *p,*s;
+       const unsigned char *p;
+       unsigned char *s;
        int i;
 
+       if (len < 1)
+               {
+               i=ASN1_R_STRING_TOO_SHORT;
+               goto err;
+               }
+
        if ((a == NULL) || ((*a) == NULL))
                {
                if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL);
@@ -185,7 +192,9 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
                if (a->data == NULL)
                        c=(unsigned char *)OPENSSL_malloc(w+1);
                else
-                       c=(unsigned char *)OPENSSL_realloc(a->data,w+1);
+                       c=(unsigned char *)OPENSSL_realloc_clean(a->data,
+                                                                a->length,
+                                                                w+1);
                if (c == NULL) return(0);
                if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length);
                a->data=c;