forked from openssh/openssh-portable
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upstream: switch config file parsing to getline(3) as this avoids
static limits noted by gerhard@; ok dtucker@, djm@ OpenBSD-Commit-ID: 6d702eabef0fa12e5a1d75c334a8c8b325298b5c
- Loading branch information
Showing
12 changed files
with
84 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: hostfile.c,v 1.71 2017/05/31 09:15:42 deraadt Exp $ */ | ||
/* $OpenBSD: hostfile.c,v 1.72 2018/06/06 18:29:18 markus Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -663,14 +663,14 @@ hostkeys_foreach(const char *path, hostkeys_foreach_fn *callback, void *ctx, | |
const char *host, const char *ip, u_int options) | ||
{ | ||
FILE *f; | ||
char line[8192], oline[8192], ktype[128]; | ||
char *line = NULL, ktype[128]; | ||
u_long linenum = 0; | ||
char *cp, *cp2; | ||
u_int kbits; | ||
int hashed; | ||
int s, r = 0; | ||
struct hostkey_foreach_line lineinfo; | ||
size_t l; | ||
size_t linesize = 0, l; | ||
|
||
memset(&lineinfo, 0, sizeof(lineinfo)); | ||
if (host == NULL && (options & HKF_WANT_MATCH) != 0) | ||
|
@@ -679,15 +679,16 @@ hostkeys_foreach(const char *path, hostkeys_foreach_fn *callback, void *ctx, | |
return SSH_ERR_SYSTEM_ERROR; | ||
|
||
debug3("%s: reading file \"%s\"", __func__, path); | ||
while (read_keyfile_line(f, path, line, sizeof(line), &linenum) == 0) { | ||
while (getline(&line, &linesize, f) != -1) { | ||
linenum++; | ||
line[strcspn(line, "\n")] = '\0'; | ||
strlcpy(oline, line, sizeof(oline)); | ||
|
||
sshkey_free(lineinfo.key); | ||
memset(&lineinfo, 0, sizeof(lineinfo)); | ||
lineinfo.path = path; | ||
lineinfo.linenum = linenum; | ||
lineinfo.line = oline; | ||
free(lineinfo.line); | ||
lineinfo.line = xstrdup(line); | ||
lineinfo.marker = MRK_NONE; | ||
lineinfo.status = HKF_STATUS_OK; | ||
lineinfo.keytype = KEY_UNSPEC; | ||
|
@@ -826,6 +827,8 @@ hostkeys_foreach(const char *path, hostkeys_foreach_fn *callback, void *ctx, | |
break; | ||
} | ||
sshkey_free(lineinfo.key); | ||
free(lineinfo.line); | ||
free(line); | ||
fclose(f); | ||
return r; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: misc.h,v 1.71 2018/03/12 00:52:01 djm Exp $ */ | ||
/* $OpenBSD: misc.h,v 1.72 2018/06/06 18:29:18 markus Exp $ */ | ||
|
||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
|
@@ -166,7 +166,6 @@ int safe_path_fd(int, const char *, struct passwd *, | |
|
||
char *read_passphrase(const char *, int); | ||
int ask_permission(const char *, ...) __attribute__((format(printf, 1, 2))); | ||
int read_keyfile_line(FILE *, const char *, char *, size_t, u_long *); | ||
|
||
#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) | ||
#define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: readconf.c,v 1.288 2018/06/01 03:33:53 djm Exp $ */ | ||
/* $OpenBSD: readconf.c,v 1.289 2018/06/06 18:29:18 markus Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -1728,7 +1728,8 @@ read_config_file_depth(const char *filename, struct passwd *pw, | |
int flags, int *activep, int depth) | ||
{ | ||
FILE *f; | ||
char line[4096]; | ||
char *line = NULL; | ||
size_t linesize = 0; | ||
int linenum; | ||
int bad_options = 0; | ||
|
||
|
@@ -1755,15 +1756,14 @@ read_config_file_depth(const char *filename, struct passwd *pw, | |
* on/off by Host specifications. | ||
*/ | ||
linenum = 0; | ||
while (fgets(line, sizeof(line), f)) { | ||
while (getline(&line, &linesize, f) != -1) { | ||
/* Update line number counter. */ | ||
linenum++; | ||
if (strlen(line) == sizeof(line) - 1) | ||
fatal("%s line %d too long", filename, linenum); | ||
if (process_config_line_depth(options, pw, host, original_host, | ||
line, filename, linenum, activep, flags, depth) != 0) | ||
bad_options++; | ||
} | ||
free(line); | ||
fclose(f); | ||
if (bad_options > 0) | ||
fatal("%s: terminating, %d bad configuration options", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
/* $OpenBSD: servconf.c,v 1.330 2018/06/06 18:23:32 djm Exp $ */ | ||
/* $OpenBSD: servconf.c,v 1.331 2018/06/06 18:29:18 markus Exp $ */ | ||
/* | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
* All rights reserved | ||
|
@@ -2103,7 +2103,8 @@ process_server_config_line(ServerOptions *options, char *line, | |
void | ||
load_server_config(const char *filename, Buffer *conf) | ||
{ | ||
char line[4096], *cp; | ||
char *line = NULL, *cp; | ||
size_t linesize = 0; | ||
FILE *f; | ||
int lineno = 0; | ||
|
||
|
@@ -2113,10 +2114,8 @@ load_server_config(const char *filename, Buffer *conf) | |
exit(1); | ||
} | ||
buffer_clear(conf); | ||
while (fgets(line, sizeof(line), f)) { | ||
while (getline(&line, &linesize, f) != -1) { | ||
lineno++; | ||
if (strlen(line) == sizeof(line) - 1) | ||
fatal("%s line %d too long", filename, lineno); | ||
/* | ||
* Trim out comments and strip whitespace | ||
* NB - preserve newlines, they are needed to reproduce | ||
|
@@ -2128,6 +2127,7 @@ load_server_config(const char *filename, Buffer *conf) | |
|
||
buffer_append(conf, cp, strlen(cp)); | ||
} | ||
free(line); | ||
buffer_append(conf, "\0", 1); | ||
fclose(f); | ||
debug2("%s: done config len = %d", __func__, buffer_len(conf)); | ||
|
Oops, something went wrong.