2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-22 18:07:25 +00:00

[master] Fix some minor issues in the dst code

This commit is contained in:
Shawn Routhier 2014-04-28 15:05:42 -07:00
parent db3f77999c
commit 0da37b4ca8
4 changed files with 33 additions and 4 deletions

View File

@ -74,6 +74,9 @@ by Eric Young (eay@cryptsoft.com).
Popelka at Red Hat. Popelka at Red Hat.
[ISC-Bugs #31892] [ISC-Bugs #31892]
- Fix some minor issues in the dst code.
[ISC-Bugs #34172]
Changes since 4.3.0rc1 Changes since 4.3.0rc1
- None - None

View 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) 1995-1998 by Trusted Information Systems, Inc.
* Portions Copyright (c) 2007,2009 by Internet Systems Consortium, Inc. ("ISC") * 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 * Permission to use, copy modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -112,6 +112,10 @@ dst_init()
} else { } else {
char *dp = (char *) malloc(len + 2); char *dp = (char *) malloc(len + 2);
int l; int l;
if (dp == NULL) {
EREPORT(("malloc() failed for dp\n"));
return;
}
memcpy(dp, s, len + 1); memcpy(dp, s, len + 1);
l = strlen (dp); l = strlen (dp);
if (dp[l - 1] != '/') { 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)); memset(new_key, 0, sizeof(*new_key));
new_key->dk_key_name = strdup(name); 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_alg = alg;
new_key->dk_flags = flags; new_key->dk_flags = flags;
new_key->dk_proto = protocol; 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)) 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)); SAFE_FREE2(pk_key->dk_key_name, strlen(pk_key->dk_key_name));
pk_key->dk_key_name = (char *) strdup(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 */ /* allocate and fill in key structure */
if (pk_key->dk_func == NULL || pk_key->dk_func->from_file_fmt == NULL) 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)); f_key->dk_alg));
} }
if (f_key->dk_KEY_struct) { 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) if (f_key->dk_key_name)
SAFE_FREE(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) { switch (mode) {
case DST_RAND_SEMI: case DST_RAND_SEMI:
bp = buff = (u_int32_t *) malloc(wanted+sizeof(u_int32_t)); 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++) { for (i = 0; i < wanted; i+= sizeof(u_int32_t), bp++) {
*bp = dst_s_quick_random(i); *bp = dst_s_quick_random(i);
} }

View 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) 1995-1998 by Trusted Information Systems, Inc.
* Portions Copyright (c) 2007,2009 by Internet Systems Consortium, Inc. ("ISC") * 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 * Permission to use, copy modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * 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); return (-4);
len = eol - p; len = eol - p;
tmp = malloc(len + 2); tmp = malloc(len + 2);
if (tmp == NULL)
return (-5);
memcpy(tmp, p, len); memcpy(tmp, p, len);
*(tmp + len) = 0x0; *(tmp + len) = 0x0;
key_len = b64_pton((char *)tmp, key, HMAC_LEN+1); /* see above */ 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; len = size > 64 ? 64 : size;
buff = malloc(len+8); buff = malloc(len+8);
if (buff == NULL)
return (-1);
n = dst_random(DST_RAND_SEMI, len, buff); n = dst_random(DST_RAND_SEMI, len, buff);
n += dst_random(DST_RAND_KEY, len, buff); n += dst_random(DST_RAND_KEY, len, buff);

View 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 $"; static const char rcsid[] = "$Header: /tmp/cvstest/DHCP/dst/prandom.c,v 1.10 2012/03/09 11:18:13 tomasz Exp $";
#endif #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) 2007,2009 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. * 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 */ if (hash->step > 1) { /* if using subset of input data */
tmp_size = size / hash->step + 2; tmp_size = size / hash->step + 2;
abuf = tp = malloc(tmp_size); abuf = tp = malloc(tmp_size);
/* no good return code but at least don't step on things */
if (tp == NULL) {
return (0);
}
tmp = tp; tmp = tp;
for (cnt = 0, i = hash->curr; i < size; i += hash->step, cnt++) for (cnt = 0, i = hash->curr; i < size; i += hash->step, cnt++)
*(tp++) = input[i]; *(tp++) = input[i];