=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/dh.c,v retrieving revision 1.63 retrieving revision 1.64 diff -u -r1.63 -r1.64 --- src/usr.bin/ssh/dh.c 2018/02/07 02:06:50 1.63 +++ src/usr.bin/ssh/dh.c 2018/06/06 18:29:18 1.64 @@ -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. * @@ -141,9 +141,9 @@ 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) { @@ -154,7 +154,7 @@ 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; @@ -172,6 +172,9 @@ if (dhg.size == best) bestcount++; } + free(line); + line = NULL; + linesize = 0; rewind(f); if (bestcount == 0) { @@ -182,7 +185,8 @@ 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) || @@ -194,6 +198,8 @@ } break; } + free(line); + line = NULL; fclose(f); if (linenum != which+1) { logit("WARNING: line %d disappeared in %s, giving up",