summaryrefslogtreecommitdiff
path: root/dh.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2018-08-24 12:49:36 +0100
committerColin Watson <cjwatson@debian.org>2018-08-30 00:57:27 +0100
commit816386e17654ca36834bebbf351419e460fad8f6 (patch)
tree3dc79d831cb73bc25b92f5a4d18f8e328c0c570a /dh.c
parent3e6f76c7039d3df22b1d0a3a5f30150efb09b69d (diff)
parent16a47fc4b04977a14f44dd433c8da1499fa80671 (diff)
New upstream release (7.8p1)
Closes: #907534
Diffstat (limited to 'dh.c')
-rw-r--r--dh.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/dh.c b/dh.c
index 46afba033..ac8d5a0ae 100644
--- a/dh.c
+++ b/dh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh.c,v 1.63 2018/02/07 02:06:50 jsing Exp $ */ 1/* $OpenBSD: dh.c,v 1.66 2018/08/04 00:55:06 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2000 Niels Provos. All rights reserved.
4 * 4 *
@@ -145,9 +145,9 @@ DH *
145choose_dh(int min, int wantbits, int max) 145choose_dh(int min, int wantbits, int max)
146{ 146{
147 FILE *f; 147 FILE *f;
148 char line[4096]; 148 char *line = NULL;
149 int best, bestcount, which; 149 size_t linesize = 0;
150 int linenum; 150 int best, bestcount, which, linenum;
151 struct dhgroup dhg; 151 struct dhgroup dhg;
152 152
153 if ((f = fopen(_PATH_DH_MODULI, "r")) == NULL) { 153 if ((f = fopen(_PATH_DH_MODULI, "r")) == NULL) {
@@ -158,7 +158,7 @@ choose_dh(int min, int wantbits, int max)
158 158
159 linenum = 0; 159 linenum = 0;
160 best = bestcount = 0; 160 best = bestcount = 0;
161 while (fgets(line, sizeof(line), f)) { 161 while (getline(&line, &linesize, f) != -1) {
162 linenum++; 162 linenum++;
163 if (!parse_prime(linenum, line, &dhg)) 163 if (!parse_prime(linenum, line, &dhg))
164 continue; 164 continue;
@@ -176,6 +176,9 @@ choose_dh(int min, int wantbits, int max)
176 if (dhg.size == best) 176 if (dhg.size == best)
177 bestcount++; 177 bestcount++;
178 } 178 }
179 free(line);
180 line = NULL;
181 linesize = 0;
179 rewind(f); 182 rewind(f);
180 183
181 if (bestcount == 0) { 184 if (bestcount == 0) {
@@ -186,7 +189,7 @@ choose_dh(int min, int wantbits, int max)
186 189
187 linenum = 0; 190 linenum = 0;
188 which = arc4random_uniform(bestcount); 191 which = arc4random_uniform(bestcount);
189 while (fgets(line, sizeof(line), f)) { 192 while (getline(&line, &linesize, f) != -1) {
190 if (!parse_prime(linenum, line, &dhg)) 193 if (!parse_prime(linenum, line, &dhg))
191 continue; 194 continue;
192 if ((dhg.size > max || dhg.size < min) || 195 if ((dhg.size > max || dhg.size < min) ||
@@ -198,6 +201,8 @@ choose_dh(int min, int wantbits, int max)
198 } 201 }
199 break; 202 break;
200 } 203 }
204 free(line);
205 line = NULL;
201 fclose(f); 206 fclose(f);
202 if (linenum != which+1) { 207 if (linenum != which+1) {
203 logit("WARNING: line %d disappeared in %s, giving up", 208 logit("WARNING: line %d disappeared in %s, giving up",
@@ -274,6 +279,7 @@ dh_gen_key(DH *dh, int need)
274 if (DH_generate_key(dh) == 0 || 279 if (DH_generate_key(dh) == 0 ||
275 !dh_pub_is_valid(dh, dh->pub_key)) { 280 !dh_pub_is_valid(dh, dh->pub_key)) {
276 BN_clear_free(dh->priv_key); 281 BN_clear_free(dh->priv_key);
282 dh->priv_key = NULL;
277 return SSH_ERR_LIBCRYPTO_ERROR; 283 return SSH_ERR_LIBCRYPTO_ERROR;
278 } 284 }
279 return 0; 285 return 0;