From 7f90635216851f6cb4bf3999e98b825f85d604f8 Mon Sep 17 00:00:00 2001 From: "markus@openbsd.org" Date: Wed, 6 Jun 2018 18:29:18 +0000 Subject: upstream: switch config file parsing to getline(3) as this avoids static limits noted by gerhard@; ok dtucker@, djm@ OpenBSD-Commit-ID: 6d702eabef0fa12e5a1d75c334a8c8b325298b5c --- authfile.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'authfile.c') diff --git a/authfile.c b/authfile.c index 57dcd808..c3a6345d 100644 --- a/authfile.c +++ b/authfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: authfile.c,v 1.128 2018/02/23 15:58:37 markus Exp $ */ +/* $OpenBSD: authfile.c,v 1.129 2018/06/06 18:29:18 markus Exp $ */ /* * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. * @@ -265,17 +265,15 @@ static int sshkey_try_load_public(struct sshkey *k, const char *filename, char **commentp) { FILE *f; - char line[SSH_MAX_PUBKEY_BYTES]; - char *cp; - u_long linenum = 0; + char *line = NULL, *cp; + size_t linesize = 0; int r; if (commentp != NULL) *commentp = NULL; if ((f = fopen(filename, "r")) == NULL) return SSH_ERR_SYSTEM_ERROR; - while (read_keyfile_line(f, filename, line, sizeof(line), - &linenum) != -1) { + while (getline(&line, &linesize, f) != -1) { cp = line; switch (*cp) { case '#': @@ -299,11 +297,13 @@ sshkey_try_load_public(struct sshkey *k, const char *filename, char **commentp) if (*commentp == NULL) r = SSH_ERR_ALLOC_FAIL; } + free(line); fclose(f); return r; } } } + free(line); fclose(f); return SSH_ERR_INVALID_FORMAT; } @@ -447,19 +447,18 @@ sshkey_in_file(struct sshkey *key, const char *filename, int strict_type, int check_ca) { FILE *f; - char line[SSH_MAX_PUBKEY_BYTES]; - char *cp; - u_long linenum = 0; + char *line = NULL, *cp; + size_t linesize = 0; int r = 0; struct sshkey *pub = NULL; + int (*sshkey_compare)(const struct sshkey *, const struct sshkey *) = strict_type ? sshkey_equal : sshkey_equal_public; if ((f = fopen(filename, "r")) == NULL) return SSH_ERR_SYSTEM_ERROR; - while (read_keyfile_line(f, filename, line, sizeof(line), - &linenum) != -1) { + while (getline(&line, &linesize, f) != -1) { cp = line; /* Skip leading whitespace. */ @@ -491,6 +490,7 @@ sshkey_in_file(struct sshkey *key, const char *filename, int strict_type, } r = SSH_ERR_KEY_NOT_FOUND; out: + free(line); sshkey_free(pub); fclose(f); return r; -- cgit v1.2.3