diff options
author | markus@openbsd.org <markus@openbsd.org> | 2018-06-06 18:29:18 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2018-06-07 04:34:05 +1000 |
commit | 7f90635216851f6cb4bf3999e98b825f85d604f8 (patch) | |
tree | ac302db18a71c1e3c5d9077d1a820e37fbc2b9b5 /dh.c | |
parent | 392db2bc83215986a91c0b65feb0e40e7619ce7e (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.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: dh.c,v 1.63 2018/02/07 02:06:50 jsing Exp $ */ +/* $OpenBSD: dh.c,v 1.64 2018/06/06 18:29:18 markus Exp $ */ /* * Copyright (c) 2000 Niels Provos. All rights reserved. * @@ -145,9 +145,9 @@ DH * choose_dh(int min, int wantbits, int max) { FILE *f; - char line[4096]; - int best, bestcount, which; - int linenum; + char *line = NULL; + size_t linesize = 0; + int best, bestcount, which, linenum; struct dhgroup dhg; if ((f = fopen(_PATH_DH_MODULI, "r")) == NULL) { @@ -158,7 +158,7 @@ choose_dh(int min, int wantbits, int max) linenum = 0; best = bestcount = 0; - while (fgets(line, sizeof(line), f)) { + while (getline(&line, &linesize, f) != -1) { linenum++; if (!parse_prime(linenum, line, &dhg)) continue; @@ -176,6 +176,9 @@ choose_dh(int min, int wantbits, int max) if (dhg.size == best) bestcount++; } + free(line); + line = NULL; + linesize = 0; rewind(f); if (bestcount == 0) { @@ -186,7 +189,8 @@ choose_dh(int min, int wantbits, int max) linenum = 0; which = arc4random_uniform(bestcount); - while (fgets(line, sizeof(line), f)) { + while (getline(&line, &linesize, f) != -1) { + linenum++; if (!parse_prime(linenum, line, &dhg)) continue; if ((dhg.size > max || dhg.size < min) || @@ -198,6 +202,8 @@ choose_dh(int min, int wantbits, int max) } break; } + free(line); + line = NULL; fclose(f); if (linenum != which+1) { logit("WARNING: line %d disappeared in %s, giving up", |