Commit a0e7c8ee authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

Add lots of checks for memory allocation failure, error codes to indicate

failure and freeing up memory if a failure occurs.

PR:620
parent a8e00b17
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -745,6 +745,10 @@

 Changes between 0.9.7e and 0.9.7f  [XX xxx XXXX]

  *) Add lots of checks for memory allocation failure, error codes to indicate
     failure and freeing up memory if a failure occurs.
     [Nauticus Networks SSL Team <openssl@nauticusnet.com>, Steve Henson]

  *) Add new -passin argument to dgst.
     [Steve Henson]

+6 −1
Original line number Diff line number Diff line
@@ -195,7 +195,12 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
			c=(unsigned char *)OPENSSL_realloc_clean(a->data,
								 a->length,
								 w+1);
		if (c == NULL) return(0);
		if (c == NULL)
			{
			ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT,ERR_R_MALLOC_FAILURE);
			return 0;
			}
  		if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length);
		if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length);
		a->data=c;
		a->length=w+1;
+6 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@
# include <sys/types.h>
#endif

#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/buffer.h>
#include <openssl/x509.h>
@@ -78,7 +79,11 @@ int ASN1_digest(int (*i2d)(), const EVP_MD *type, char *data,
	unsigned char *str,*p;

	i=i2d(data,NULL);
	if ((str=(unsigned char *)OPENSSL_malloc(i)) == NULL) return(0);
	if ((str=(unsigned char *)OPENSSL_malloc(i)) == NULL)
		{
		ASN1err(ASN1_F_ASN1_DIGEST,ERR_R_MALLOC_FAILURE);
		return(0);
		}
	p=str;
	i2d(data,&p);

+1 −1
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
		unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
		if (!new_data)
			{
			ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
			ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
			goto err;
			}
		ret->data=new_data;
+9 −3
Original line number Diff line number Diff line
@@ -192,8 +192,9 @@ int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
		{
		if (s != NULL)
			{
			ASN1_STRING_set((ASN1_STRING *)s,
				(unsigned char *)str,t.length);
			if (!ASN1_STRING_set((ASN1_STRING *)s,
				(unsigned char *)str,t.length))
				return 0;
			s->type=V_ASN1_GENERALIZEDTIME;
			}
		return(1);
@@ -223,7 +224,12 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
	if ((p == NULL) || ((size_t)s->length < len))
		{
		p=OPENSSL_malloc(len);
		if (p == NULL) return(NULL);
		if (p == NULL)
			{
			ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_SET,
				ERR_R_MALLOC_FAILURE);
			return(NULL);
			}
		if (s->data != NULL)
			OPENSSL_free(s->data);
		s->data=(unsigned char *)p;
Loading