From af155d91d9605de98989770e7ef03b7033ce9f7c Mon Sep 17 00:00:00 2001 From: cameronrich Date: Sat, 11 Feb 2012 11:30:45 +0000 Subject: [PATCH] Some fixes after going through the test harness git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@222 9a5d90b5-6617-0410-8a86-bb477d3ed2e3 --- crypto/crypto_misc.c | 7 ++++++- ssl/asn1.c | 44 ++++++++++++++++++++++---------------------- ssl/loader.c | 2 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/crypto/crypto_misc.c b/crypto/crypto_misc.c index 92e24c951..0902fab05 100644 --- a/crypto/crypto_misc.c +++ b/crypto/crypto_misc.c @@ -349,14 +349,19 @@ EXP_FUNC int STDCALL base64_decode(const char *in, int len, y = t = 0; } - if (z >= *outlen) /* check that we don't go past the output buffer */ + /* check that we don't go past the output buffer */ + if (outlen && z >= *outlen) + { + printf("Stuff %d, %d\n", z, *outlen); goto error; + } } if (y != 0) goto error; *outlen = z; + ret = 0; error: diff --git a/ssl/asn1.c b/ssl/asn1.c index 92ed7d11f..f3e17a37b 100644 --- a/ssl/asn1.c +++ b/ssl/asn1.c @@ -291,34 +291,34 @@ static int asn1_get_printable_str(const uint8_t *buf, int *offset, char **str) int asn1_type = buf[*offset]; /* some certs have this awful crud in them for some reason */ - if (buf[asn1_type] != ASN1_PRINTABLE_STR && - buf[asn1_type] != ASN1_PRINTABLE_STR2 && - buf[asn1_type] != ASN1_TELETEX_STR && - buf[asn1_type] != ASN1_IA5_STR && - buf[asn1_type] != ASN1_UNICODE_STR) + if (asn1_type != ASN1_PRINTABLE_STR && + asn1_type != ASN1_PRINTABLE_STR2 && + asn1_type != ASN1_TELETEX_STR && + asn1_type != ASN1_IA5_STR && + asn1_type != ASN1_UNICODE_STR) goto end_pnt_str; - (*offset)++; - len = get_asn1_length(buf, offset); + (*offset)++; + len = get_asn1_length(buf, offset); - if (buf[asn1_type - 1] == ASN1_UNICODE_STR) - { - int i; - *str = (char *)malloc(len/2+1); /* allow for null */ + if (asn1_type == ASN1_UNICODE_STR) + { + int i; + *str = (char *)malloc(len/2+1); /* allow for null */ - for (i = 0; i < len; i += 2) - (*str)[i/2] = buf[*offset + i + 1]; + for (i = 0; i < len; i += 2) + (*str)[i/2] = buf[*offset + i + 1]; - (*str)[len/2] = 0; /* null terminate */ - } - else - { - *str = (char *)malloc(len+1); /* allow for null */ - memcpy(*str, &buf[*offset], len); - (*str)[len] = 0; /* null terminate */ - } + (*str)[len/2] = 0; /* null terminate */ + } + else + { + *str = (char *)malloc(len+1); /* allow for null */ + memcpy(*str, &buf[*offset], len); + (*str)[len] = 0; /* null terminate */ + } - *offset += len; + *offset += len; end_pnt_str: return len; diff --git a/ssl/loader.c b/ssl/loader.c index 18f3347f8..333fb18e9 100644 --- a/ssl/loader.c +++ b/ssl/loader.c @@ -259,7 +259,6 @@ static int pem_decrypt(const char *where, const char *end, /* turn base64 into binary */ pem_size = (int)(end-start); - ssl_obj->len = sizeof(ssl_obj->buf); if (base64_decode(start, pem_size, ssl_obj->buf, &ssl_obj->len) != 0) goto error; @@ -315,6 +314,7 @@ static int new_pem_obj(SSL_CTX *ssl_ctx, int is_cacert, char *where, /* 4/3 bigger than what we need but so what */ ssl_obj->buf = (uint8_t *)calloc(1, pem_size); + ssl_obj->len = pem_size; if (i == IS_RSA_PRIVATE_KEY && strstr(start, "Proc-Type:") &&