diff options
author | markus@openbsd.org <markus@openbsd.org> | 2020-06-24 15:09:53 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2020-06-26 15:18:44 +1000 |
commit | 250246fef22b87a54a63211c60a2def9be431fbd (patch) | |
tree | 1e60f1b1c82548d82e8c8a06192ba16bd6b5eb7b /servconf.c | |
parent | 89b54900ac61986760452f132bbe3fb7249cfdac (diff) |
upstream: support loading big sshd_config files w/o realloc; ok
djm
OpenBSD-Commit-ID: ba9238e810074ac907f0cf8cee1737ac04983171
Diffstat (limited to 'servconf.c')
-rw-r--r-- | servconf.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/servconf.c b/servconf.c index bd8df7fce..22cb9583f 100644 --- a/servconf.c +++ b/servconf.c | |||
@@ -1,5 +1,5 @@ | |||
1 | 1 | ||
2 | /* $OpenBSD: servconf.c,v 1.365 2020/05/27 22:37:53 djm Exp $ */ | 2 | /* $OpenBSD: servconf.c,v 1.366 2020/06/24 15:09:53 markus Exp $ */ |
3 | /* | 3 | /* |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
5 | * All rights reserved | 5 | * All rights reserved |
@@ -15,6 +15,7 @@ | |||
15 | 15 | ||
16 | #include <sys/types.h> | 16 | #include <sys/types.h> |
17 | #include <sys/socket.h> | 17 | #include <sys/socket.h> |
18 | #include <sys/stat.h> | ||
18 | #ifdef __OpenBSD__ | 19 | #ifdef __OpenBSD__ |
19 | #include <sys/sysctl.h> | 20 | #include <sys/sysctl.h> |
20 | #endif | 21 | #endif |
@@ -2395,6 +2396,7 @@ process_server_config_line(ServerOptions *options, char *line, | |||
2395 | void | 2396 | void |
2396 | load_server_config(const char *filename, struct sshbuf *conf) | 2397 | load_server_config(const char *filename, struct sshbuf *conf) |
2397 | { | 2398 | { |
2399 | struct stat st; | ||
2398 | char *line = NULL, *cp; | 2400 | char *line = NULL, *cp; |
2399 | size_t linesize = 0; | 2401 | size_t linesize = 0; |
2400 | FILE *f; | 2402 | FILE *f; |
@@ -2406,6 +2408,10 @@ load_server_config(const char *filename, struct sshbuf *conf) | |||
2406 | exit(1); | 2408 | exit(1); |
2407 | } | 2409 | } |
2408 | sshbuf_reset(conf); | 2410 | sshbuf_reset(conf); |
2411 | /* grow buffer, so realloc is avoided for large config files */ | ||
2412 | if (fstat(fileno(f), &st) == 0 && st.st_size > 0 && | ||
2413 | (r = sshbuf_allocate(conf, st.st_size)) != 0) | ||
2414 | fatal("%s: allocate failed: %s", __func__, ssh_err(r)); | ||
2409 | while (getline(&line, &linesize, f) != -1) { | 2415 | while (getline(&line, &linesize, f) != -1) { |
2410 | lineno++; | 2416 | lineno++; |
2411 | /* | 2417 | /* |