diff options
author | Damien Miller <djm@mindrot.org> | 2007-10-26 14:26:32 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2007-10-26 14:26:32 +1000 |
commit | 0f4ed693d655429ad544b36c7305216d155a2d4b (patch) | |
tree | 39db4ff797fc1199990b0f1735b8af47ccc509b2 /ssh-keygen.c | |
parent | b8c98076283a43e21dc53580837f3296c186ecd6 (diff) |
- chl@cvs.openbsd.org 2007/10/02 17:49:58
[ssh-keygen.c]
handles zero-sized strings that fgets can return
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r-- | ssh-keygen.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c index 2b2399c50..657937629 100644 --- a/ssh-keygen.c +++ b/ssh-keygen.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh-keygen.c,v 1.162 2007/09/11 15:47:17 gilles Exp $ */ | 1 | /* $OpenBSD: ssh-keygen.c,v 1.163 2007/10/02 17:49:58 chl 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 |
@@ -535,8 +535,7 @@ do_fingerprint(struct passwd *pw) | |||
535 | f = fopen(identity_file, "r"); | 535 | f = fopen(identity_file, "r"); |
536 | if (f != NULL) { | 536 | if (f != NULL) { |
537 | while (fgets(line, sizeof(line), f)) { | 537 | while (fgets(line, sizeof(line), f)) { |
538 | i = strlen(line) - 1; | 538 | if ((cp = strchr(line, '\n')) == NULL) { |
539 | if (line[i] != '\n') { | ||
540 | error("line %d too long: %.40s...", num, line); | 539 | error("line %d too long: %.40s...", num, line); |
541 | skip = 1; | 540 | skip = 1; |
542 | continue; | 541 | continue; |
@@ -546,7 +545,7 @@ do_fingerprint(struct passwd *pw) | |||
546 | skip = 0; | 545 | skip = 0; |
547 | continue; | 546 | continue; |
548 | } | 547 | } |
549 | line[i] = '\0'; | 548 | *cp = '\0'; |
550 | 549 | ||
551 | /* Skip leading whitespace, empty and comment lines. */ | 550 | /* Skip leading whitespace, empty and comment lines. */ |
552 | for (cp = line; *cp == ' ' || *cp == '\t'; cp++) | 551 | for (cp = line; *cp == ' ' || *cp == '\t'; cp++) |
@@ -614,7 +613,7 @@ do_known_hosts(struct passwd *pw, const char *name) | |||
614 | Key *public; | 613 | Key *public; |
615 | char *cp, *cp2, *kp, *kp2; | 614 | char *cp, *cp2, *kp, *kp2; |
616 | char line[16*1024], tmp[MAXPATHLEN], old[MAXPATHLEN]; | 615 | char line[16*1024], tmp[MAXPATHLEN], old[MAXPATHLEN]; |
617 | int c, i, skip = 0, inplace = 0, num = 0, invalid = 0, has_unhashed = 0; | 616 | int c, skip = 0, inplace = 0, num = 1, invalid = 0, has_unhashed = 0; |
618 | 617 | ||
619 | if (!have_identity) { | 618 | if (!have_identity) { |
620 | cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid); | 619 | cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid); |
@@ -649,19 +648,18 @@ do_known_hosts(struct passwd *pw, const char *name) | |||
649 | } | 648 | } |
650 | 649 | ||
651 | while (fgets(line, sizeof(line), in)) { | 650 | while (fgets(line, sizeof(line), in)) { |
652 | num++; | 651 | if ((cp = strchr(line, '\n')) == NULL) { |
653 | i = strlen(line) - 1; | ||
654 | if (line[i] != '\n') { | ||
655 | error("line %d too long: %.40s...", num, line); | 652 | error("line %d too long: %.40s...", num, line); |
656 | skip = 1; | 653 | skip = 1; |
657 | invalid = 1; | 654 | invalid = 1; |
658 | continue; | 655 | continue; |
659 | } | 656 | } |
657 | num++; | ||
660 | if (skip) { | 658 | if (skip) { |
661 | skip = 0; | 659 | skip = 0; |
662 | continue; | 660 | continue; |
663 | } | 661 | } |
664 | line[i] = '\0'; | 662 | *cp = '\0'; |
665 | 663 | ||
666 | /* Skip leading whitespace, empty and comment lines. */ | 664 | /* Skip leading whitespace, empty and comment lines. */ |
667 | for (cp = line; *cp == ' ' || *cp == '\t'; cp++) | 665 | for (cp = line; *cp == ' ' || *cp == '\t'; cp++) |