summaryrefslogtreecommitdiff
path: root/hostfile.c
diff options
context:
space:
mode:
authormarkus@openbsd.org <markus@openbsd.org>2018-06-06 18:29:18 +0000
committerDamien Miller <djm@mindrot.org>2018-06-07 04:34:05 +1000
commit7f90635216851f6cb4bf3999e98b825f85d604f8 (patch)
treeac302db18a71c1e3c5d9077d1a820e37fbc2b9b5 /hostfile.c
parent392db2bc83215986a91c0b65feb0e40e7619ce7e (diff)
upstream: switch config file parsing to getline(3) as this avoids
static limits noted by gerhard@; ok dtucker@, djm@ OpenBSD-Commit-ID: 6d702eabef0fa12e5a1d75c334a8c8b325298b5c
Diffstat (limited to 'hostfile.c')
-rw-r--r--hostfile.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/hostfile.c b/hostfile.c
index 12f174ff9..e08339379 100644
--- a/hostfile.c
+++ b/hostfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hostfile.c,v 1.71 2017/05/31 09:15:42 deraadt Exp $ */ 1/* $OpenBSD: hostfile.c,v 1.72 2018/06/06 18:29:18 markus Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -663,14 +663,14 @@ hostkeys_foreach(const char *path, hostkeys_foreach_fn *callback, void *ctx,
663 const char *host, const char *ip, u_int options) 663 const char *host, const char *ip, u_int options)
664{ 664{
665 FILE *f; 665 FILE *f;
666 char line[8192], oline[8192], ktype[128]; 666 char *line = NULL, ktype[128];
667 u_long linenum = 0; 667 u_long linenum = 0;
668 char *cp, *cp2; 668 char *cp, *cp2;
669 u_int kbits; 669 u_int kbits;
670 int hashed; 670 int hashed;
671 int s, r = 0; 671 int s, r = 0;
672 struct hostkey_foreach_line lineinfo; 672 struct hostkey_foreach_line lineinfo;
673 size_t l; 673 size_t linesize = 0, l;
674 674
675 memset(&lineinfo, 0, sizeof(lineinfo)); 675 memset(&lineinfo, 0, sizeof(lineinfo));
676 if (host == NULL && (options & HKF_WANT_MATCH) != 0) 676 if (host == NULL && (options & HKF_WANT_MATCH) != 0)
@@ -679,15 +679,16 @@ hostkeys_foreach(const char *path, hostkeys_foreach_fn *callback, void *ctx,
679 return SSH_ERR_SYSTEM_ERROR; 679 return SSH_ERR_SYSTEM_ERROR;
680 680
681 debug3("%s: reading file \"%s\"", __func__, path); 681 debug3("%s: reading file \"%s\"", __func__, path);
682 while (read_keyfile_line(f, path, line, sizeof(line), &linenum) == 0) { 682 while (getline(&line, &linesize, f) != -1) {
683 linenum++;
683 line[strcspn(line, "\n")] = '\0'; 684 line[strcspn(line, "\n")] = '\0';
684 strlcpy(oline, line, sizeof(oline));
685 685
686 sshkey_free(lineinfo.key); 686 sshkey_free(lineinfo.key);
687 memset(&lineinfo, 0, sizeof(lineinfo)); 687 memset(&lineinfo, 0, sizeof(lineinfo));
688 lineinfo.path = path; 688 lineinfo.path = path;
689 lineinfo.linenum = linenum; 689 lineinfo.linenum = linenum;
690 lineinfo.line = oline; 690 free(lineinfo.line);
691 lineinfo.line = xstrdup(line);
691 lineinfo.marker = MRK_NONE; 692 lineinfo.marker = MRK_NONE;
692 lineinfo.status = HKF_STATUS_OK; 693 lineinfo.status = HKF_STATUS_OK;
693 lineinfo.keytype = KEY_UNSPEC; 694 lineinfo.keytype = KEY_UNSPEC;
@@ -826,6 +827,8 @@ hostkeys_foreach(const char *path, hostkeys_foreach_fn *callback, void *ctx,
826 break; 827 break;
827 } 828 }
828 sshkey_free(lineinfo.key); 829 sshkey_free(lineinfo.key);
830 free(lineinfo.line);
831 free(line);
829 fclose(f); 832 fclose(f);
830 return r; 833 return r;
831} 834}