Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/agc-netpgp-standalone]: src/crypto/external/bsd/netpgp/dist/src Do some ...



details:   https://anonhg.NetBSD.org/src/rev/22099ac9b954
branches:  agc-netpgp-standalone
changeset: 777828:22099ac9b954
user:      agc <agc%NetBSD.org@localhost>
date:      Mon Oct 29 15:46:49 2012 +0000

description:
Do some argument checking in public functions (exported by library interface)

diffstat:

 crypto/external/bsd/netpgp/dist/src/libbn/bignum.c     |  22 +++++--
 crypto/external/bsd/netpgp/dist/src/libbn/misc.c       |  14 +++-
 crypto/external/bsd/netpgp/dist/src/libdigest/digest.c |  53 ++++++++++++++---
 crypto/external/bsd/netpgp/dist/src/libdigest/tiger.c  |  21 +++++-
 crypto/external/bsd/netpgp/dist/src/librsa/rsa.c       |  23 ++++++-
 crypto/external/bsd/netpgp/dist/src/libverify/b64.c    |   6 ++
 6 files changed, 111 insertions(+), 28 deletions(-)

diffs (truncated from 432 to 300 lines):

diff -r e308a1c14492 -r 22099ac9b954 crypto/external/bsd/netpgp/dist/src/libbn/bignum.c
--- a/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c        Sat Oct 27 02:27:50 2012 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c        Mon Oct 29 15:46:49 2012 +0000
@@ -5270,13 +5270,15 @@
 void
 BN_swap(BIGNUM *a, BIGNUM *b)
 {
-       mp_exch(a, b);
+       if (a && b) {
+               mp_exch(a, b);
+       }
 }
 
 int
 BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
 {
-       if (a == NULL || n < 0) {
+       if (r == NULL || a == NULL || n < 0) {
                return 0;
        }
        BN_copy(r, a);
@@ -5286,7 +5288,7 @@
 int
 BN_lshift1(BIGNUM *r, BIGNUM *a)
 {
-       if (a == NULL) {
+       if (r == NULL || a == NULL) {
                return 0;
        }
        BN_copy(r, a);
@@ -5296,7 +5298,7 @@
 int
 BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
 {
-       if (a == NULL || n < 0) {
+       if (r == NULL || a == NULL || n < 0) {
                return MP_VAL;
        }
        BN_copy(r, a);
@@ -5306,7 +5308,7 @@
 int
 BN_rshift1(BIGNUM *r, BIGNUM *a)
 {
-       if (a == NULL) {
+       if (r == NULL || a == NULL) {
                return 0;
        }
        BN_copy(r, a);
@@ -5316,6 +5318,9 @@
 int
 BN_set_word(BIGNUM *a, BN_ULONG w)
 {
+       if (a == NULL) {
+               return 0;
+       }
        mp_set(a, w);
        return 1;
 }
@@ -5509,13 +5514,13 @@
 char *
 BN_bn2hex(const BIGNUM *a)
 {
-       return formatbn(a, 16);
+       return (a == NULL) ? NULL : formatbn(a, 16);
 }
 
 char *
 BN_bn2dec(const BIGNUM *a)
 {
-       return formatbn(a, 10);
+       return (a == NULL) ? NULL : formatbn(a, 10);
 }
 
 #ifndef _KERNEL
@@ -5542,6 +5547,9 @@
        int             digits;
        int             i;
 
+       if (rnd == NULL) {
+               return 0;
+       }
        mp_init_size(rnd, digits = howmany(bits, DIGIT_BIT));
        for (i = 0 ; i < digits ; i++) {
                r = (uint64_t)arc4random();
diff -r e308a1c14492 -r 22099ac9b954 crypto/external/bsd/netpgp/dist/src/libbn/misc.c
--- a/crypto/external/bsd/netpgp/dist/src/libbn/misc.c  Sat Oct 27 02:27:50 2012 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/libbn/misc.c  Mon Oct 29 15:46:49 2012 +0000
@@ -73,9 +73,11 @@
        va_list args;
 
        USE_ARG(level);
-       va_start(args, fmt);
-       vfprintf(stderr, fmt, args);
-       va_end(args);
+       if (fmt != NULL) {
+               va_start(args, fmt);
+               vfprintf(stderr, fmt, args);
+               va_end(args);
+       }
 }
 #endif
 
@@ -91,6 +93,12 @@
        size_t  i;
        char    line[LINELEN + 1];
 
+       if (src == NULL) {
+               return;
+       }
+       if (fp == NULL) {
+               fp = stdout;
+       }
        (void) fprintf(fp, "%s%s", (header) ? header : "", (header) ? "\n" : "");
        (void) fprintf(fp, "[%" PRIsize "u char%s]\n", length, (length == 1) ? "" : "s");
        for (i = 0 ; i < length ; i++) {
diff -r e308a1c14492 -r 22099ac9b954 crypto/external/bsd/netpgp/dist/src/libdigest/digest.c
--- a/crypto/external/bsd/netpgp/dist/src/libdigest/digest.c    Sat Oct 27 02:27:50 2012 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/libdigest/digest.c    Mon Oct 29 15:46:49 2012 +0000
@@ -89,55 +89,73 @@
 void                                                                                                                 
 MD5_Init(MD5_CTX *context)
 {
-       MD5Init(context);
+       if (context) {
+               MD5Init(context);
+       }
 }
 
 void                                                                                                                 
 MD5_Update(MD5_CTX *context, const unsigned char *data, unsigned int len)
 {
-       MD5Update(context, data, len);
+       if (context && data) {
+               MD5Update(context, data, len);
+       }
 }
 
 void                                                                                                                 
 MD5_Final(unsigned char digest[16], MD5_CTX *context)
 {
-       MD5Final(digest, context);
+       if (digest && context) {
+               MD5Final(digest, context);
+       }
 }
 
 void                                                                                                                 
 SHA1_Init(SHA1_CTX *context)
 {
-       SHA1Init(context);
+       if (context) {
+               SHA1Init(context);
+       }
 }
 
 void                                                                                                                 
 SHA1_Update(SHA1_CTX *context, const unsigned char *data, unsigned int len)
 {
-       SHA1Update(context, data, len);
+       if (context && data) {
+               SHA1Update(context, data, len);
+       }
 }
 
 void                                                                                                                 
 SHA1_Final(unsigned char digest[20], SHA1_CTX *context)
 {
-       SHA1Final(digest, context);
+       if (digest && context) {
+               SHA1Final(digest, context);
+       }
 }
 
 void                                                                                                                 
 RMD160_Init(RMD160_CTX *context)
 {
-       RMD160Init(context);
+       if (context) {
+               RMD160Init(context);
+       }
 }
 
 void                                                                                                                 
 RMD160_Update(RMD160_CTX *context, const unsigned char *data, unsigned int len)
 {
-       RMD160Update(context, data, len);
+       if (context && data) {
+               RMD160Update(context, data, len);
+       }
 }
 
 void                                                                                                                 
 RMD160_Final(unsigned char digest[20], RMD160_CTX *context)
 {
-       RMD160Final(digest, context);
+       if (context && digest) {
+               RMD160Final(digest, context);
+       }
 }
 
 
@@ -169,6 +187,9 @@
 int 
 digest_init(digest_t *hash, const uint32_t hashalg)
 {
+       if (hash == NULL) {
+               return 0;
+       }
        switch(hash->alg = hashalg) {
        case MD5_HASH_ALG:
                MD5Init(&hash->u.md5ctx);
@@ -247,7 +268,7 @@
 {
        rec_t   *r;
 
-       for (r = hashalgs ; r->s ; r++) {
+       for (r = hashalgs ; hashalg && r->s ; r++) {
                if (strcasecmp(r->s, hashalg) == 0) {
                        return r->alg;
                }
@@ -258,6 +279,9 @@
 int 
 digest_update(digest_t *hash, const uint8_t *data, size_t length)
 {
+       if (hash == NULL || data == NULL) {
+               return 0;
+       }
        switch(hash->alg) {
        case MD5_HASH_ALG:
                MD5Update(hash->ctx, data, (unsigned)length);
@@ -287,6 +311,9 @@
 unsigned 
 digest_final(uint8_t *out, digest_t *hash)
 {
+       if (hash == NULL || out == NULL) {
+               return 0;
+       }
        switch(hash->alg) {
        case MD5_HASH_ALG:
                MD5Final(out, hash->ctx);
@@ -319,6 +346,9 @@
 {
        uint8_t          trailer[6];
 
+       if (hash == NULL) {
+               return 0;
+       }
        trailer[0] = V4_SIGNATURE;
        trailer[1] = 0xFF;
        trailer[2] = (uint8_t)((hashedlen >> 24) & 0xff);
@@ -332,6 +362,9 @@
 unsigned
 digest_get_prefix(unsigned hashalg, uint8_t *prefix, size_t size)
 {
+       if (prefix == NULL) {
+               return 0;
+       }
        switch (hashalg) {
        case MD5_HASH_ALG:
                memcpy(prefix, prefix_md5, sizeof(prefix_md5));
diff -r e308a1c14492 -r 22099ac9b954 crypto/external/bsd/netpgp/dist/src/libdigest/tiger.c
--- a/crypto/external/bsd/netpgp/dist/src/libdigest/tiger.c     Sat Oct 27 02:27:50 2012 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/libdigest/tiger.c     Mon Oct 29 15:46:49 2012 +0000
@@ -753,13 +753,17 @@
 void
 TIGER_Init(TIGER_CTX *ctx)
 {
-       initcontext(ctx, 0x01);
+       if (ctx) {
+               initcontext(ctx, 0x01);
+       }
 }
 
 void
 TIGER2_Init(TIGER_CTX *ctx)
 {
-       initcontext(ctx, 0x80);
+       if (ctx) {
+               initcontext(ctx, 0x80);
+       }
 }
 
 void
@@ -774,6 +778,9 @@
        } u;
        int              indian = 1;
 
+       if (ctx == NULL || data == NULL) {
+               return;
+       }
        for(i = length; i >= 64; i -= 64) {
                if (IS_BIG_ENDIAN(indian)) {
                        for (j = 0; j < 64; j++) {
@@ -823,6 +830,9 @@
        int             indian = 1;
        int             i;
 
+       if (digest == NULL || ctx == NULL) {
+               return;
+       }



Home | Main Index | Thread Index | Old Index