From cb3d998301cdc61d8a26373fd1b8bcb90da56af1 Mon Sep 17 00:00:00 2001 From: toddouska Date: Fri, 1 Jun 2012 15:55:41 -0700 Subject: [PATCH] asn checks --- ctaocrypt/src/asn.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index d12a47a86..c2b40b5ba 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -63,6 +63,16 @@ enum { #endif +#ifndef min + + static INLINE word32 min(word32 a, word32 b) + { + return a > b ? b : a; + } + +#endif /* min */ + + #ifdef THREADX /* uses parital structures */ #define XTIME(tl) (0) @@ -2710,7 +2720,7 @@ static int SetMyVersion(word32 version, byte* output, int header) } output[i++] = ASN_INTEGER; output[i++] = 0x01; - output[i++] = version; + output[i++] = (byte)version; return i; } @@ -3183,8 +3193,6 @@ static const char* GetOneName(CertName* name, int idx) default: return 0; } - - return 0; } @@ -3220,8 +3228,6 @@ static byte GetNameId(int idx) default: return 0; } - - return 0; } @@ -3508,7 +3514,8 @@ static int WriteCertBody(DerCert* der, byte* buffer) idx += der->publicKeySz; if (der->extensionsSz) { /* extensions */ - XMEMCPY(buffer + idx, der->extensions, der->extensionsSz); + XMEMCPY(buffer + idx, der->extensions, min(der->extensionsSz, + sizeof(der->extensions))); idx += der->extensionsSz; }