]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[master] Fix some minor issues in the dst code
authorShawn Routhier <sar@isc.org>
Mon, 28 Apr 2014 22:05:42 +0000 (15:05 -0700)
committerShawn Routhier <sar@isc.org>
Mon, 28 Apr 2014 22:05:42 +0000 (15:05 -0700)
RELNOTES
dst/dst_api.c
dst/hmac_link.c
dst/prandom.c

index ea32a3541fdb298ffd66212eb6a3d065e09d1667..3960563dd46991a4f5697d5542bf17a915ff3c26 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -74,6 +74,9 @@ by Eric Young (eay@cryptsoft.com).
   Popelka at Red Hat.
   [ISC-Bugs #31892]
 
+- Fix some minor issues in the dst code.
+  [ISC-Bugs #34172]
+
                        Changes since 4.3.0rc1
 
 - None
index ddaf50fcfe718c2b6b85e4da6b79ab1cecac4163..f667e69df8bec11da79d547f7c5ce0caf07fd02c 100644 (file)
@@ -5,7 +5,7 @@ static const char rcsid[] = "$Header: /tmp/cvstest/DHCP/dst/dst_api.c,v 1.10 201
 /*
  * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
  * Portions Copyright (c) 2007,2009 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 2012-2013 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 2012-2014 by Internet Systems Consortium, Inc. ("ISC")
  *
  * Permission to use, copy modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -112,6 +112,10 @@ dst_init()
                } else {
                        char *dp = (char *) malloc(len + 2);
                        int l;
+                       if (dp == NULL) {
+                               EREPORT(("malloc() failed for dp\n"));
+                               return;
+                       }
                        memcpy(dp, s, len + 1);
                        l = strlen (dp);
                        if (dp[l - 1] != '/') {
@@ -180,6 +184,11 @@ dst_s_get_key_struct(const char *name, const int alg, const u_int32_t flags,
 
        memset(new_key, 0, sizeof(*new_key));
        new_key->dk_key_name = strdup(name);
+       if (new_key->dk_key_name == NULL) {
+               EREPORT(("Unable to duplicate name for key"));
+               free(new_key);
+               return (NULL);
+       }
        new_key->dk_alg = alg;
        new_key->dk_flags = flags;
        new_key->dk_proto = protocol;
@@ -903,6 +912,10 @@ dst_s_read_private_key_file(char *name, DST_KEY *pk_key, unsigned in_id,
        if (pk_key->dk_key_name && !strcmp(pk_key->dk_key_name, name))
                SAFE_FREE2(pk_key->dk_key_name, strlen(pk_key->dk_key_name));
        pk_key->dk_key_name = (char *) strdup(name);
+       if (pk_key->dk_key_name == NULL) {
+               EREPORT(("Unable to duplicate name for key"));
+               goto fail;
+       }
 
        /* allocate and fill in key structure */
        if (pk_key->dk_func == NULL || pk_key->dk_func->from_file_fmt == NULL)
@@ -1014,7 +1027,7 @@ dst_free_key(DST_KEY *f_key)
                         f_key->dk_alg));
        }
        if (f_key->dk_KEY_struct) {
-               SAFE_FREE(f_key->dk_KEY_struct);
+               SAFE_FREE2(f_key->dk_KEY_struct, sizeof(f_key->dk_KEY_struct));
        }
        if (f_key->dk_key_name)
                SAFE_FREE(f_key->dk_key_name);
@@ -1069,6 +1082,10 @@ dst_random(const int mode, unsigned wanted, u_char *outran)
        switch (mode) {
        case DST_RAND_SEMI: 
                bp = buff = (u_int32_t *) malloc(wanted+sizeof(u_int32_t));
+               if (bp == NULL) {
+                       EREPORT(("malloc() failed for buff in function dst_random\n"));
+                       return (0);
+               }
                for (i = 0; i < wanted; i+= sizeof(u_int32_t), bp++) {
                        *bp = dst_s_quick_random(i);
                }
index 1fa36caf3bdec9630ff330a3342968db539f82e8..784661f636f506566cc4e0f76258f3acad58e278 100644 (file)
@@ -5,7 +5,7 @@ static const char rcsid[] = "$Header: /tmp/cvstest/DHCP/dst/hmac_link.c,v 1.6 20
 /*
  * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
  * Portions Copyright (c) 2007,2009 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 2012,2014 by Internet Systems Consortium, Inc. ("ISC")
  *
  * Permission to use, copy modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -355,6 +355,9 @@ dst_hmac_md5_key_from_file_format(DST_KEY *dkey, const char *buff,
                return (-4);
        len = eol - p;
        tmp = malloc(len + 2);
+       if (tmp == NULL)
+               return (-5);
+
        memcpy(tmp, p, len);
        *(tmp + len) = 0x0;
        key_len = b64_pton((char *)tmp, key, HMAC_LEN+1);       /* see above */
@@ -447,6 +450,8 @@ dst_hmac_md5_generate_key(DST_KEY *key, const int nothing)
        
        len = size > 64 ? 64 : size;
        buff = malloc(len+8);
+       if (buff == NULL)
+               return (-1);
 
        n = dst_random(DST_RAND_SEMI, len, buff);
        n += dst_random(DST_RAND_KEY, len, buff);
index fbb9a200ccb8f1f4b9399975131356f907d94516..340010db7c032f45e23bebdab6ab3e5d40cd8c84 100644 (file)
@@ -2,7 +2,7 @@
 static const char rcsid[] = "$Header: /tmp/cvstest/DHCP/dst/prandom.c,v 1.10 2012/03/09 11:18:13 tomasz Exp $";
 #endif
 /*
- * Portions Copyright (c) 2012,2013 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 2012,2013-2014 by Internet Systems Consortium, Inc. ("ISC")
  * Portions Copyright (c) 2007,2009 by Internet Systems Consortium, Inc. ("ISC")
  * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
  *
@@ -549,6 +549,10 @@ do_hash(dst_work *work, prand_hash *hash, const u_char *input, unsigned size)
        if (hash->step > 1) {   /* if using subset of input data */
                tmp_size = size / hash->step + 2;
                abuf = tp = malloc(tmp_size);
+               /* no good return code but at least don't step on things */
+               if (tp == NULL) {
+                       return (0);
+               }
                tmp = tp;
                for (cnt = 0, i = hash->curr; i < size; i += hash->step, cnt++)
                        *(tp++) = input[i];