summaryrefslogtreecommitdiff
path: root/hostfile.c
diff options
context:
space:
mode:
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}