Blame SOURCES/openssl-1.0.1e-cve-2015-0289.patch

96beb5
diff -up openssl-1.0.1e/crypto/pkcs7/pk7_doit.c.pkcs7-null-deref openssl-1.0.1e/crypto/pkcs7/pk7_doit.c
96beb5
--- openssl-1.0.1e/crypto/pkcs7/pk7_doit.c.pkcs7-null-deref	2013-02-11 16:26:04.000000000 +0100
96beb5
+++ openssl-1.0.1e/crypto/pkcs7/pk7_doit.c	2015-03-18 18:54:10.064871658 +0100
96beb5
@@ -272,6 +272,27 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
96beb5
 	PKCS7_RECIP_INFO *ri=NULL;
96beb5
 	ASN1_OCTET_STRING *os=NULL;
96beb5
 
96beb5
+	if (p7 == NULL)
96beb5
+		{
96beb5
+		PKCS7err(PKCS7_F_PKCS7_DATAINIT, PKCS7_R_INVALID_NULL_POINTER);
96beb5
+		return NULL;
96beb5
+		}
96beb5
+	/*
96beb5
+	 * The content field in the PKCS7 ContentInfo is optional, but that really
96beb5
+	 * only applies to inner content (precisely, detached signatures).
96beb5
+	 *
96beb5
+	 * When reading content, missing outer content is therefore treated as an
96beb5
+	 * error.
96beb5
+	 *
96beb5
+	 * When creating content, PKCS7_content_new() must be called before
96beb5
+	 * calling this method, so a NULL p7->d is always an error.
96beb5
+	 */
96beb5
+	if (p7->d.ptr == NULL)
96beb5
+		{
96beb5
+		PKCS7err(PKCS7_F_PKCS7_DATAINIT, PKCS7_R_NO_CONTENT);
96beb5
+		return NULL;
96beb5
+		}
96beb5
+
96beb5
 	i=OBJ_obj2nid(p7->type);
96beb5
 	p7->state=PKCS7_S_HEADER;
96beb5
 
96beb5
@@ -433,6 +454,18 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKE
96beb5
        unsigned char *ek = NULL, *tkey = NULL;
96beb5
        int eklen = 0, tkeylen = 0;
96beb5
 
96beb5
+	if (p7 == NULL)
96beb5
+		{
96beb5
+		PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_INVALID_NULL_POINTER);
96beb5
+		return NULL;
96beb5
+		}
96beb5
+
96beb5
+	if (p7->d.ptr == NULL)
96beb5
+		{
96beb5
+		PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_NO_CONTENT);
96beb5
+		return NULL;
96beb5
+		}
96beb5
+
96beb5
 	i=OBJ_obj2nid(p7->type);
96beb5
 	p7->state=PKCS7_S_HEADER;
96beb5
 
96beb5
@@ -440,6 +473,12 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKE
96beb5
 		{
96beb5
 	case NID_pkcs7_signed:
96beb5
 		data_body=PKCS7_get_octet_string(p7->d.sign->contents);
96beb5
+		if (!PKCS7_is_detached(p7) && data_body == NULL)
96beb5
+			{
96beb5
+			PKCS7err(PKCS7_F_PKCS7_DATADECODE,
96beb5
+				PKCS7_R_NO_CONTENT);
96beb5
+			goto err;
96beb5
+			}
96beb5
 		md_sk=p7->d.sign->md_algs;
96beb5
 		break;
96beb5
 	case NID_pkcs7_signedAndEnveloped:
96beb5
@@ -747,6 +786,18 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
96beb5
 	STACK_OF(PKCS7_SIGNER_INFO) *si_sk=NULL;
96beb5
 	ASN1_OCTET_STRING *os=NULL;
96beb5
 
96beb5
+	if (p7 == NULL)
96beb5
+		{
96beb5
+		PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_INVALID_NULL_POINTER);
96beb5
+		return 0;
96beb5
+		}
96beb5
+
96beb5
+	if (p7->d.ptr == NULL)
96beb5
+		{
96beb5
+		PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_NO_CONTENT);
96beb5
+		return 0;
96beb5
+		}
96beb5
+
96beb5
 	EVP_MD_CTX_init(&ctx_tmp);
96beb5
 	i=OBJ_obj2nid(p7->type);
96beb5
 	p7->state=PKCS7_S_HEADER;
96beb5
@@ -791,6 +842,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
96beb5
 		/* If detached data then the content is excluded */
96beb5
 		if(PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) {
96beb5
 			M_ASN1_OCTET_STRING_free(os);
96beb5
+			os = NULL;
96beb5
 			p7->d.sign->contents->d.data = NULL;
96beb5
 		}
96beb5
 		break;
96beb5
@@ -801,6 +853,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
96beb5
 		if(PKCS7_type_is_data(p7->d.digest->contents) && p7->detached)
96beb5
 			{
96beb5
 			M_ASN1_OCTET_STRING_free(os);
96beb5
+			os = NULL;
96beb5
 			p7->d.digest->contents->d.data = NULL;
96beb5
 			}
96beb5
 		break;
96beb5
@@ -873,23 +926,32 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
96beb5
 		M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data, md_len);
96beb5
 		}
96beb5
 
96beb5
-	if (!PKCS7_is_detached(p7) && !(os->flags & ASN1_STRING_FLAG_NDEF))
96beb5
+	if (!PKCS7_is_detached(p7))
96beb5
 		{
96beb5
-		char *cont;
96beb5
-		long contlen;
96beb5
-		btmp=BIO_find_type(bio,BIO_TYPE_MEM);
96beb5
-		if (btmp == NULL)
96beb5
-			{
96beb5
-			PKCS7err(PKCS7_F_PKCS7_DATAFINAL,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
96beb5
+		/*
96beb5
+		 * NOTE(emilia): I think we only reach os == NULL here because detached
96beb5
+		 * digested data support is broken.
96beb5
+		 */
96beb5
+		if (os == NULL)
96beb5
 			goto err;
96beb5
+		if (!(os->flags & ASN1_STRING_FLAG_NDEF))
96beb5
+			{
96beb5
+			char *cont;
96beb5
+			long contlen;
96beb5
+			btmp=BIO_find_type(bio,BIO_TYPE_MEM);
96beb5
+			if (btmp == NULL)
96beb5
+				{
96beb5
+				PKCS7err(PKCS7_F_PKCS7_DATAFINAL,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
96beb5
+				goto err;
96beb5
+				}
96beb5
+			contlen = BIO_get_mem_data(btmp, &cont;;
96beb5
+			/* Mark the BIO read only then we can use its copy of the data
96beb5
+			 * instead of making an extra copy.
96beb5
+			 */
96beb5
+			BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY);
96beb5
+			BIO_set_mem_eof_return(btmp, 0);
96beb5
+			ASN1_STRING_set0(os, (unsigned char *)cont, contlen);
96beb5
 			}
96beb5
-		contlen = BIO_get_mem_data(btmp, &cont;;
96beb5
-		/* Mark the BIO read only then we can use its copy of the data
96beb5
-		 * instead of making an extra copy.
96beb5
-		 */
96beb5
-		BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY);
96beb5
-		BIO_set_mem_eof_return(btmp, 0);
96beb5
-		ASN1_STRING_set0(os, (unsigned char *)cont, contlen);
96beb5
 		}
96beb5
 	ret=1;
96beb5
 err:
96beb5
@@ -928,6 +990,7 @@ int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_
96beb5
 	if (EVP_DigestSignUpdate(&mctx,abuf,alen) <= 0)
96beb5
 		goto err;
96beb5
 	OPENSSL_free(abuf);
96beb5
+	abuf = NULL;
96beb5
 	if (EVP_DigestSignFinal(&mctx, NULL, &siglen) <= 0)
96beb5
 		goto err;
96beb5
 	abuf = OPENSSL_malloc(siglen);
96beb5
@@ -965,6 +1028,18 @@ int PKCS7_dataVerify(X509_STORE *cert_st
96beb5
 	STACK_OF(X509) *cert;
96beb5
 	X509 *x509;
96beb5
 
96beb5
+	if (p7 == NULL)
96beb5
+		{
96beb5
+		PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, PKCS7_R_INVALID_NULL_POINTER);
96beb5
+		return 0;
96beb5
+		}
96beb5
+
96beb5
+	if (p7->d.ptr == NULL)
96beb5
+		{
96beb5
+		PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, PKCS7_R_NO_CONTENT);
96beb5
+		return 0;
96beb5
+		}
96beb5
+
96beb5
 	if (PKCS7_type_is_signed(p7))
96beb5
 		{
96beb5
 		cert=p7->d.sign->cert;
96beb5
diff -up openssl-1.0.1e/crypto/pkcs7/pk7_lib.c.pkcs7-null-deref openssl-1.0.1e/crypto/pkcs7/pk7_lib.c
96beb5
--- openssl-1.0.1e/crypto/pkcs7/pk7_lib.c.pkcs7-null-deref	2013-02-11 16:26:04.000000000 +0100
96beb5
+++ openssl-1.0.1e/crypto/pkcs7/pk7_lib.c	2015-03-18 18:05:58.398767116 +0100
96beb5
@@ -459,6 +459,8 @@ int PKCS7_set_digest(PKCS7 *p7, const EV
96beb5
 
96beb5
 STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7)
96beb5
 	{
96beb5
+	if (p7 == NULL || p7->d.ptr == NULL)
96beb5
+		return NULL;
96beb5
 	if (PKCS7_type_is_signed(p7))
96beb5
 		{
96beb5
 		return(p7->d.sign->signer_info);