Browse Source

Memory leak and NULL dereference fixes.

PR#3403

(Imported from upstream's e42c208235)

Change-Id: Ibcdd8c95604f661055bfb1e91b15fd3686a04c0d
kris/onging/CECPQ3_patch15
Adam Langley 10 years ago
parent
commit
7893c008e6
5 changed files with 30 additions and 7 deletions
  1. +14
    -5
      crypto/asn1/a_utctm.c
  2. +3
    -0
      crypto/asn1/bio_asn1.c
  3. +6
    -1
      crypto/asn1/tasn_enc.c
  4. +5
    -1
      crypto/pkcs8/p5_pbev2.c
  5. +2
    -0
      crypto/x509/t_x509.c

+ 14
- 5
crypto/asn1/a_utctm.c View File

@@ -224,24 +224,29 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
struct tm *ts;
struct tm data;
size_t len = 20;
int free_s = 0;

if (s == NULL)
{
free_s = 1;
s=M_ASN1_UTCTIME_new();
}
if (s == NULL)
return(NULL);
goto err;


ts=OPENSSL_gmtime(&t, &data);
if (ts == NULL)
return(NULL);
goto err;

if (offset_day || offset_sec)
{
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
return NULL;
goto err;
}

if((ts->tm_year < 50) || (ts->tm_year >= 150))
return NULL;
goto err;

p=(char *)s->data;
if ((p == NULL) || ((size_t)s->length < len))
@@ -250,7 +255,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
if (p == NULL)
{
OPENSSL_PUT_ERROR(ASN1, ASN1_UTCTIME_adj, ERR_R_MALLOC_FAILURE);
return(NULL);
goto err;
}
if (s->data != NULL)
OPENSSL_free(s->data);
@@ -262,6 +267,10 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
s->length=strlen(p);
s->type=V_ASN1_UTCTIME;
return(s);
err:
if (free_s && s)
M_ASN1_UTCTIME_free(s);
return NULL;
}




+ 3
- 0
crypto/asn1/bio_asn1.c View File

@@ -151,7 +151,10 @@ static int asn1_bio_new(BIO *b)
if (!ctx)
return 0;
if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE))
{
OPENSSL_free(ctx);
return 0;
}
b->init = 1;
b->ptr = (char *)ctx;
b->flags = 0;


+ 6
- 1
crypto/asn1/tasn_enc.c View File

@@ -450,9 +450,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 */


+ 5
- 1
crypto/pkcs8/p5_pbev2.c View File

@@ -88,7 +88,11 @@ static 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);
}


+ 2
- 0
crypto/x509/t_x509.c View File

@@ -463,6 +463,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);


Loading…
Cancel
Save