From bb298a0e23a617bc84b92276467064c1a5c5882c Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Sun, 17 Jul 2005 19:16:35 +0000 Subject: [PATCH] Fix missing initialisation of big numbers. BN_hex2bn behaves differently if the passed pointer points to NULL or not. Noticed-by: Michal Belczyk (slightly different patch commited) --- crypto/telnet/libtelnet/pk.c | 7 +++++-- usr.sbin/keyserv/setkey.c | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crypto/telnet/libtelnet/pk.c b/crypto/telnet/libtelnet/pk.c index 355a13eee8..e062f8746d 100644 --- a/crypto/telnet/libtelnet/pk.c +++ b/crypto/telnet/libtelnet/pk.c @@ -28,7 +28,7 @@ * * * $FreeBSD: src/crypto/telnet/libtelnet/pk.c,v 1.2.2.4 2002/08/24 07:28:35 nsayer Exp $ - * $DragonFly: src/crypto/telnet/libtelnet/pk.c,v 1.3 2005/01/11 13:22:41 joerg Exp $ + * $DragonFly: src/crypto/telnet/libtelnet/pk.c,v 1.4 2005/07/17 19:16:35 joerg Exp $ */ /* public key routines */ @@ -130,10 +130,13 @@ common_key(char *xsecret, char *xpublic, IdeaData *ideakey, DesData *deskey) if ((ctx = BN_CTX_new()) == NULL) errx(1, "could not create BN_CTX"); + modulus = NULL; if (BN_hex2bn(&modulus, HEXMODULUS) == NULL) errx(1, "could not convert modulus"); + public = NULL; if (BN_hex2bn(&public, xpublic) == NULL) errx(1, "could not convert public"); + secret = NULL; if (BN_hex2bn(&secret, xsecret) == NULL) errx(1, "could not convert secret"); @@ -195,7 +198,7 @@ genkeys(char *public, char *secret) char *xkey; BN_CTX *ctx; - BIGNUM *pk, *sk, *tmp, *base, *root, *modulus; + BIGNUM *pk, *sk, *tmp, *base, *root, *modulus = NULL; pk = itobn(0); sk = itobn(0); diff --git a/usr.sbin/keyserv/setkey.c b/usr.sbin/keyserv/setkey.c index d27a0ca3ef..d231b3d02e 100644 --- a/usr.sbin/keyserv/setkey.c +++ b/usr.sbin/keyserv/setkey.c @@ -28,7 +28,7 @@ * * @(#)setkey.c 1.11 94/04/25 SMI * $FreeBSD: src/usr.sbin/keyserv/setkey.c,v 1.3 1999/08/28 01:16:41 peter Exp $ - * $DragonFly: src/usr.sbin/keyserv/setkey.c,v 1.8 2005/01/11 13:22:40 joerg Exp $ + * $DragonFly: src/usr.sbin/keyserv/setkey.c,v 1.9 2005/07/17 19:16:35 joerg Exp $ */ /* @@ -82,6 +82,7 @@ pk_nodefaultkeys(void) void setmodulus(char *modx) { + modulus = NULL; if (BN_hex2bn(&modulus, modx) == NULL) errx(1, "could not convert modulus to BIGNUM: %s", ERR_error_string(ERR_get_error(), 0)); @@ -181,10 +182,12 @@ pk_crypt(uid_t uid, char *remote_name, netobj *remote_key, des_block *key, if (!readcache(xpublic, xsecret, &deskey)) { if ((ctx = BN_CTX_new()) == NULL) return (KEY_SYSTEMERR); + public = NULL; if (BN_hex2bn(&public, xpublic) == NULL) { BN_CTX_free(ctx); return (KEY_SYSTEMERR); } + secret = NULL; if (BN_hex2bn(&secret, xsecret) == NULL) { BN_free(public); BN_CTX_free(ctx); @@ -240,10 +243,12 @@ pk_get_conv_key(uid_t uid, keybuf xpublic, cryptkeyres *result) if (!readcache(xpublic, xsecret, &result->cryptkeyres_u.deskey)) { if ((ctx = BN_CTX_new()) == NULL) return (KEY_SYSTEMERR); + public = NULL; if (BN_hex2bn(&public, xpublic) == NULL) { BN_CTX_free(ctx); return (KEY_SYSTEMERR); } + secret = NULL; if (BN_hex2bn(&secret, xsecret) == NULL) { BN_free(public); BN_CTX_free(ctx); -- 2.32.0