summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 2568c00e8..ccebbaf76 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.316 2018/06/01 04:21:29 djm Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.317 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) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -870,7 +870,8 @@ do_fingerprint(struct passwd *pw)
870{ 870{
871 FILE *f; 871 FILE *f;
872 struct sshkey *public = NULL; 872 struct sshkey *public = NULL;
873 char *comment = NULL, *cp, *ep, line[SSH_MAX_PUBKEY_BYTES]; 873 char *comment = NULL, *cp, *ep, *line = NULL;
874 size_t linesize = 0;
874 int i, invalid = 1; 875 int i, invalid = 1;
875 const char *path; 876 const char *path;
876 u_long lnum = 0; 877 u_long lnum = 0;
@@ -885,7 +886,8 @@ do_fingerprint(struct passwd *pw)
885 } else if ((f = fopen(path, "r")) == NULL) 886 } else if ((f = fopen(path, "r")) == NULL)
886 fatal("%s: %s: %s", __progname, path, strerror(errno)); 887 fatal("%s: %s: %s", __progname, path, strerror(errno));
887 888
888 while (read_keyfile_line(f, path, line, sizeof(line), &lnum) == 0) { 889 while (getline(&line, &linesize, f) != -1) {
890 lnum++;
889 cp = line; 891 cp = line;
890 cp[strcspn(cp, "\n")] = '\0'; 892 cp[strcspn(cp, "\n")] = '\0';
891 /* Trim leading space and comments */ 893 /* Trim leading space and comments */
@@ -905,6 +907,7 @@ do_fingerprint(struct passwd *pw)
905 */ 907 */
906 if (lnum == 1 && strcmp(identity_file, "-") != 0 && 908 if (lnum == 1 && strcmp(identity_file, "-") != 0 &&
907 strstr(cp, "PRIVATE KEY") != NULL) { 909 strstr(cp, "PRIVATE KEY") != NULL) {
910 free(line);
908 fclose(f); 911 fclose(f);
909 fingerprint_private(path); 912 fingerprint_private(path);
910 exit(0); 913 exit(0);
@@ -951,6 +954,7 @@ do_fingerprint(struct passwd *pw)
951 invalid = 0; /* One good key in the file is sufficient */ 954 invalid = 0; /* One good key in the file is sufficient */
952 } 955 }
953 fclose(f); 956 fclose(f);
957 free(line);
954 958
955 if (invalid) 959 if (invalid)
956 fatal("%s is not a public key file.", path); 960 fatal("%s is not a public key file.", path);
@@ -2004,8 +2008,9 @@ do_show_cert(struct passwd *pw)
2004 struct stat st; 2008 struct stat st;
2005 int r, is_stdin = 0, ok = 0; 2009 int r, is_stdin = 0, ok = 0;
2006 FILE *f; 2010 FILE *f;
2007 char *cp, line[SSH_MAX_PUBKEY_BYTES]; 2011 char *cp, *line = NULL;
2008 const char *path; 2012 const char *path;
2013 size_t linesize = 0;
2009 u_long lnum = 0; 2014 u_long lnum = 0;
2010 2015
2011 if (!have_identity) 2016 if (!have_identity)
@@ -2021,7 +2026,8 @@ do_show_cert(struct passwd *pw)
2021 } else if ((f = fopen(identity_file, "r")) == NULL) 2026 } else if ((f = fopen(identity_file, "r")) == NULL)
2022 fatal("fopen %s: %s", identity_file, strerror(errno)); 2027 fatal("fopen %s: %s", identity_file, strerror(errno));
2023 2028
2024 while (read_keyfile_line(f, path, line, sizeof(line), &lnum) == 0) { 2029 while (getline(&line, &linesize, f) != -1) {
2030 lnum++;
2025 sshkey_free(key); 2031 sshkey_free(key);
2026 key = NULL; 2032 key = NULL;
2027 /* Trim leading space and comments */ 2033 /* Trim leading space and comments */
@@ -2046,6 +2052,7 @@ do_show_cert(struct passwd *pw)
2046 printf("%s:%lu:\n", path, lnum); 2052 printf("%s:%lu:\n", path, lnum);
2047 print_cert(key); 2053 print_cert(key);
2048 } 2054 }
2055 free(line);
2049 sshkey_free(key); 2056 sshkey_free(key);
2050 fclose(f); 2057 fclose(f);
2051 exit(ok ? 0 : 1); 2058 exit(ok ? 0 : 1);
@@ -2077,7 +2084,8 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca,
2077{ 2084{
2078 struct sshkey *key = NULL; 2085 struct sshkey *key = NULL;
2079 u_long lnum = 0; 2086 u_long lnum = 0;
2080 char *path, *cp, *ep, line[SSH_MAX_PUBKEY_BYTES]; 2087 char *path, *cp, *ep, *line = NULL;
2088 size_t linesize = 0;
2081 unsigned long long serial, serial2; 2089 unsigned long long serial, serial2;
2082 int i, was_explicit_key, was_sha1, r; 2090 int i, was_explicit_key, was_sha1, r;
2083 FILE *krl_spec; 2091 FILE *krl_spec;
@@ -2092,8 +2100,8 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca,
2092 2100
2093 if (!quiet) 2101 if (!quiet)
2094 printf("Revoking from %s\n", path); 2102 printf("Revoking from %s\n", path);
2095 while (read_keyfile_line(krl_spec, path, line, sizeof(line), 2103 while (getline(&line, &linesize, krl_spec) != -1) {
2096 &lnum) == 0) { 2104 lnum++;
2097 was_explicit_key = was_sha1 = 0; 2105 was_explicit_key = was_sha1 = 0;
2098 cp = line + strspn(line, " \t"); 2106 cp = line + strspn(line, " \t");
2099 /* Trim trailing space, comments and strip \n */ 2107 /* Trim trailing space, comments and strip \n */
@@ -2193,6 +2201,7 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca,
2193 } 2201 }
2194 if (strcmp(path, "-") != 0) 2202 if (strcmp(path, "-") != 0)
2195 fclose(krl_spec); 2203 fclose(krl_spec);
2204 free(line);
2196 free(path); 2205 free(path);
2197} 2206}
2198 2207