summaryrefslogtreecommitdiff
path: root/dh.c
diff options
context:
space:
mode:
authormillert@openbsd.org <millert@openbsd.org>2018-09-17 15:40:14 +0000
committerDamien Miller <djm@mindrot.org>2018-09-20 14:00:11 +1000
commit5e532320e9e51de720d5f3cc2596e95d29f6e98f (patch)
tree9e8a666d8c8f3c2badc1e0050b51552891a8e793 /dh.c
parentcce8cbe0ed7d1ba3a575310e0b63c193326ae616 (diff)
upstream: When choosing a prime from the moduli file, avoid
re-using the linenum variable for something that is not a line number to avoid the confusion that resulted in the bug in rev. 1.64. This also lets us pass the actual linenum to parse_prime() so the error messages include the correct line number. OK markus@ some time ago. OpenBSD-Commit-ID: 4d8e5d3e924d6e8eb70053e3defa23c151a00084
Diffstat (limited to 'dh.c')
-rw-r--r--dh.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/dh.c b/dh.c
index f3ed38829..657b32da3 100644
--- a/dh.c
+++ b/dh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh.c,v 1.66 2018/08/04 00:55:06 djm Exp $ */ 1/* $OpenBSD: dh.c,v 1.68 2018/09/17 15:40:14 millert Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2000 Niels Provos. All rights reserved.
4 * 4 *
@@ -188,15 +188,17 @@ choose_dh(int min, int wantbits, int max)
188 logit("WARNING: no suitable primes in %s", _PATH_DH_MODULI); 188 logit("WARNING: no suitable primes in %s", _PATH_DH_MODULI);
189 return (dh_new_group_fallback(max)); 189 return (dh_new_group_fallback(max));
190 } 190 }
191 which = arc4random_uniform(bestcount);
191 192
192 linenum = 0; 193 linenum = 0;
193 which = arc4random_uniform(bestcount); 194 bestcount = 0;
194 while (getline(&line, &linesize, f) != -1) { 195 while (getline(&line, &linesize, f) != -1) {
196 linenum++;
195 if (!parse_prime(linenum, line, &dhg)) 197 if (!parse_prime(linenum, line, &dhg))
196 continue; 198 continue;
197 if ((dhg.size > max || dhg.size < min) || 199 if ((dhg.size > max || dhg.size < min) ||
198 dhg.size != best || 200 dhg.size != best ||
199 linenum++ != which) { 201 bestcount++ != which) {
200 BN_clear_free(dhg.g); 202 BN_clear_free(dhg.g);
201 BN_clear_free(dhg.p); 203 BN_clear_free(dhg.p);
202 continue; 204 continue;
@@ -206,9 +208,9 @@ choose_dh(int min, int wantbits, int max)
206 free(line); 208 free(line);
207 line = NULL; 209 line = NULL;
208 fclose(f); 210 fclose(f);
209 if (linenum != which+1) { 211 if (bestcount != which + 1) {
210 logit("WARNING: line %d disappeared in %s, giving up", 212 logit("WARNING: selected prime disappeared in %s, giving up",
211 which, _PATH_DH_MODULI); 213 _PATH_DH_MODULI);
212 return (dh_new_group_fallback(max)); 214 return (dh_new_group_fallback(max));
213 } 215 }
214 216