Memory leak and NULL dereference fixes.
authorDr. Stephen Henson <steve@openssl.org>
Fri, 27 Jun 2014 02:21:10 +0000 (03:21 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 27 Jun 2014 14:33:18 +0000 (15:33 +0100)
PR#3403
(cherry picked from commit d2aea038297e0c64ca66e6844cbb37377365885e)

Conflicts:

apps/crl2p7.c
crypto/asn1/a_utctm.c
crypto/asn1/ameth_lib.c
crypto/asn1/bio_asn1.c

apps/apps.c
apps/ca.c
apps/crl2p7.c
crypto/asn1/asn_mime.c
crypto/asn1/asn_pack.c
crypto/asn1/evp_asn1.c
crypto/asn1/t_x509.c
crypto/asn1/tasn_enc.c

index ce8d9c9a7d1f049bce1f18006d709b173ff27b20..792b2540f3932128e282ddce0152da17b2f42b07 100644 (file)
@@ -362,6 +362,8 @@ int chopup_args(ARGS *arg, char *buf, int *argc, char **argv[])
                {
                arg->count=20;
                arg->data=(char **)OPENSSL_malloc(sizeof(char *)*arg->count);
+               if (arg->data == NULL)
+                       return 0;
                }
        for (i=0; i<arg->count; i++)
                arg->data[i]=NULL;
@@ -1429,6 +1431,8 @@ char *make_config_name()
 
        len=strlen(t)+strlen(OPENSSL_CONF)+2;
        p=OPENSSL_malloc(len);
+       if (p == NULL)
+               return NULL;
        BUF_strlcpy(p,t,len);
 #ifndef OPENSSL_SYS_VMS
        BUF_strlcat(p,"/",len);
index 651c5a648afcc144d5f5be8067ecf126809d02fb..d6984ba8fdedcf051170d223840b9d95ec42bc99 100644 (file)
--- a/apps/ca.c
+++ b/apps/ca.c
@@ -2751,6 +2751,9 @@ char *make_revocation_str(int rev_type, char *rev_arg)
 
        revtm = X509_gmtime_adj(NULL, 0);
 
+       if (!revtm)
+               return NULL;
+
        i = revtm->length + 1;
 
        if (reason) i += strlen(reason) + 1;
index b2f2d121d56cb8739f32d6b9a6173051fdd98d55..f164a3ad94484bd0599fb74552288c0b50b8cb9e 100644 (file)
@@ -142,7 +142,13 @@ int MAIN(int argc, char **argv)
                        {
                        if (--argc < 1) goto bad;
                        if(!certflst) certflst = sk_new_null();
-                       sk_push(certflst,*(++argv));
+                       if (!certflst)
+                               goto end;
+                       if (!sk_push(certflst,*(++argv)))
+                               {
+                               sk_free(certflst);
+                               goto end;
+                               }
                        }
                else
                        {
index ad8fbed90725a38c40c7f6e09b930dde0843d098..095887f27d647fdbe2d369bc8aa805fb93d2e4eb 100644 (file)
@@ -595,6 +595,8 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
        int len, state, save_state = 0;
 
        headers = sk_MIME_HEADER_new(mime_hdr_cmp);
+       if (!headers)
+               return NULL;
        while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
        /* If whitespace at line start then continuation line */
        if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME;
index f1a5a056322766f8e782f771b65b753050ecd2bb..c373714b687b797cc8d5adb24511daf5a071c713 100644 (file)
@@ -134,15 +134,23 @@ ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d, ASN1_STRING **oct)
                
        if (!(octmp->length = i2d(obj, NULL))) {
                ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
-               return NULL;
+               goto err;
        }
        if (!(p = OPENSSL_malloc (octmp->length))) {
                ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
-               return NULL;
+               goto err;
        }
        octmp->data = p;
        i2d (obj, &p);
        return octmp;
+       err:
+       if (!oct || !*oct)
+               {
+               ASN1_STRING_free(octmp);
+               if (oct)
+                       *oct = NULL;
+               }
+       return NULL;
 }
 
 #endif
index f3d9804860ec31fc09d885f18f3c6e3e47ad00da..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);
        }
index 6f295b4e145c50bcf91b61d5537c90554e8ada9c..f9dad0e6fac277fa2829bf1c2a90e59aca40ba76 100644 (file)
@@ -465,6 +465,8 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
        l=80-2-obase;
 
        b=X509_NAME_oneline(name,NULL,0);
+       if (!b)
+               return 0;
        if (!*b)
                {
                OPENSSL_free(b);
index 2721f904a633e9e976d577a347846a35483d0747..b3687f9f1c5177d2fe80143a1ae4d5a434fd2b00 100644 (file)
@@ -453,9 +453,14 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
                        {
                        derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk)
                                                * sizeof(*derlst));
+                       if (!derlst)
+                               return 0;
                        tmpdat = OPENSSL_malloc(skcontlen);
-                       if (!derlst || !tmpdat)
+                       if (!tmpdat)
+                               {
+                               OPENSSL_free(derlst);
                                return 0;
+                               }
                        }
                }
        /* If not sorting just output each item */