mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-28 16:24:39 +02:00
upstream: support loading big sshd_config files w/o realloc; ok
djm OpenBSD-Commit-ID: ba9238e810074ac907f0cf8cee1737ac04983171
This commit is contained in:
parent
89b54900ac
commit
250246fef2
@ -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 <ylo@cs.hut.fi>, Espoo, Finland
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||||
* All rights reserved
|
* All rights reserved
|
||||||
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
@ -2395,6 +2396,7 @@ process_server_config_line(ServerOptions *options, char *line,
|
|||||||
void
|
void
|
||||||
load_server_config(const char *filename, struct sshbuf *conf)
|
load_server_config(const char *filename, struct sshbuf *conf)
|
||||||
{
|
{
|
||||||
|
struct stat st;
|
||||||
char *line = NULL, *cp;
|
char *line = NULL, *cp;
|
||||||
size_t linesize = 0;
|
size_t linesize = 0;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
@ -2406,6 +2408,10 @@ load_server_config(const char *filename, struct sshbuf *conf)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
sshbuf_reset(conf);
|
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) {
|
while (getline(&line, &linesize, f) != -1) {
|
||||||
lineno++;
|
lineno++;
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user