=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/servconf.c,v retrieving revision 1.365 retrieving revision 1.366 diff -u -r1.365 -r1.366 --- src/usr.bin/ssh/servconf.c 2020/05/27 22:37:53 1.365 +++ src/usr.bin/ssh/servconf.c 2020/06/24 15:09:53 1.366 @@ -1,5 +1,5 @@ -/* $OpenBSD: servconf.c,v 1.365 2020/05/27 22:37:53 djm Exp $ */ +/* $OpenBSD: servconf.c,v 1.366 2020/06/24 15:09:53 markus Exp $ */ /* * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland * All rights reserved @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -2324,6 +2325,7 @@ void load_server_config(const char *filename, struct sshbuf *conf) { + struct stat st; char *line = NULL, *cp; size_t linesize = 0; FILE *f; @@ -2335,6 +2337,10 @@ exit(1); } sshbuf_reset(conf); + /* grow buffer, so realloc is avoided for large config files */ + if (fstat(fileno(f), &st) == 0 && st.st_size > 0 && + (r = sshbuf_allocate(conf, st.st_size)) != 0) + fatal("%s: allocate failed: %s", __func__, ssh_err(r)); while (getline(&line, &linesize, f) != -1) { lineno++; /*