summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorCharles Longeau <chl@cvs.openbsd.org>2007-10-02 17:49:59 +0000
committerCharles Longeau <chl@cvs.openbsd.org>2007-10-02 17:49:59 +0000
commiteb6fed1cbd08ba3a924ef05d18e17023b3dab4bc (patch)
tree2da272e10ec2c0d26403b65d9f0a815b5c2f6c49 /usr.bin
parentf3f5cc33f4c49620a5642dda3391cfa5baa929f2 (diff)
handles zero-sized strings that fgets can return
properly removes trailing newline removes an unused variable correctly counts line number "looks ok" ray@ markus@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ssh/ssh-keygen.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/usr.bin/ssh/ssh-keygen.c b/usr.bin/ssh/ssh-keygen.c
index fb4261ae6c0..6e338947446 100644
--- a/usr.bin/ssh/ssh-keygen.c
+++ b/usr.bin/ssh/ssh-keygen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keygen.c,v 1.162 2007/09/11 15:47:17 gilles Exp $ */
+/* $OpenBSD: ssh-keygen.c,v 1.163 2007/10/02 17:49:58 chl Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -528,8 +528,7 @@ do_fingerprint(struct passwd *pw)
f = fopen(identity_file, "r");
if (f != NULL) {
while (fgets(line, sizeof(line), f)) {
- i = strlen(line) - 1;
- if (line[i] != '\n') {
+ if ((cp = strchr(line, '\n')) == NULL) {
error("line %d too long: %.40s...", num, line);
skip = 1;
continue;
@@ -539,7 +538,7 @@ do_fingerprint(struct passwd *pw)
skip = 0;
continue;
}
- line[i] = '\0';
+ *cp = '\0';
/* Skip leading whitespace, empty and comment lines. */
for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
@@ -607,7 +606,7 @@ do_known_hosts(struct passwd *pw, const char *name)
Key *public;
char *cp, *cp2, *kp, *kp2;
char line[16*1024], tmp[MAXPATHLEN], old[MAXPATHLEN];
- int c, i, skip = 0, inplace = 0, num = 0, invalid = 0, has_unhashed = 0;
+ int c, skip = 0, inplace = 0, num = 1, invalid = 0, has_unhashed = 0;
if (!have_identity) {
cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid);
@@ -642,19 +641,18 @@ do_known_hosts(struct passwd *pw, const char *name)
}
while (fgets(line, sizeof(line), in)) {
- num++;
- i = strlen(line) - 1;
- if (line[i] != '\n') {
+ if ((cp = strchr(line, '\n')) == NULL) {
error("line %d too long: %.40s...", num, line);
skip = 1;
invalid = 1;
continue;
}
+ num++;
if (skip) {
skip = 0;
continue;
}
- line[i] = '\0';
+ *cp = '\0';
/* Skip leading whitespace, empty and comment lines. */
for (cp = line; *cp == ' ' || *cp == '\t'; cp++)