upstream: invalidate dh->priv_key after freeing it in error path;

avoids unlikely double-free later. Reported by Viktor Dukhovni via
https://github.com/openssh/openssh-portable/pull/96 feedback jsing@ tb@

OpenBSD-Commit-ID: e317eb17c3e05500ae851f279ef6486f0457c805
This commit is contained in:
djm@openbsd.org 2018-08-04 00:55:06 +00:00 committed by Damien Miller
parent 74287f5df9
commit 967226a1bd

3
dh.c
View File

@ -1,4 +1,4 @@
/* $OpenBSD: dh.c,v 1.65 2018/06/26 11:23:59 millert Exp $ */
/* $OpenBSD: dh.c,v 1.66 2018/08/04 00:55:06 djm Exp $ */
/*
* Copyright (c) 2000 Niels Provos. All rights reserved.
*
@ -279,6 +279,7 @@ dh_gen_key(DH *dh, int need)
if (DH_generate_key(dh) == 0 ||
!dh_pub_is_valid(dh, dh->pub_key)) {
BN_clear_free(dh->priv_key);
dh->priv_key = NULL;
return SSH_ERR_LIBCRYPTO_ERROR;
}
return 0;