summaryrefslogtreecommitdiff
path: root/dh.c
diff options
context:
space:
mode:
authormarkus@openbsd.org <markus@openbsd.org>2018-06-06 18:29:18 +0000
committerDamien Miller <djm@mindrot.org>2018-06-07 04:34:05 +1000
commit7f90635216851f6cb4bf3999e98b825f85d604f8 (patch)
treeac302db18a71c1e3c5d9077d1a820e37fbc2b9b5 /dh.c
parent392db2bc83215986a91c0b65feb0e40e7619ce7e (diff)
upstream: switch config file parsing to getline(3) as this avoids
static limits noted by gerhard@; ok dtucker@, djm@ OpenBSD-Commit-ID: 6d702eabef0fa12e5a1d75c334a8c8b325298b5c
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..16eb13276 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.64 2018/06/06 18:29:18 markus 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,8 @@ 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) {
193 linenum++;
190 if (!parse_prime(linenum, line, &dhg)) 194 if (!parse_prime(linenum, line, &dhg))
191 continue; 195 continue;
192 if ((dhg.size > max || dhg.size < min) || 196 if ((dhg.size > max || dhg.size < min) ||
@@ -198,6 +202,8 @@ choose_dh(int min, int wantbits, int max)
198 } 202 }
199 break; 203 break;
200 } 204 }
205 free(line);
206 line = NULL;
201 fclose(f); 207 fclose(f);
202 if (linenum != which+1) { 208 if (linenum != which+1) {
203 logit("WARNING: line %d disappeared in %s, giving up", 209 logit("WARNING: line %d disappeared in %s, giving up",