diff options
author | djm@openbsd.org <djm@openbsd.org> | 2017-03-03 06:13:11 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2017-03-09 11:21:20 +0000 |
commit | 78800aa252da1ebbfb55f7e593f43c337e694cc3 (patch) | |
tree | b3a25ac6aa302a04a5361754165ef953bd2b115f /ssh-keygen.c | |
parent | e18d2ba71e6bf009c53e65509da84b712c300471 (diff) |
upstream commit
fix ssh-keygen -H accidentally corrupting known_hosts that
contained already-hashed entries. HKF_MATCH_HOST_HASHED is only set by
hostkeys_foreach() when hostname matching is in use, so we need to look for
the hash marker explicitly.
Upstream-ID: da82ad653b93e8a753580d3cf5cd448bc2520528
Origin: https://anongit.mindrot.org/openssh.git/commit/?id=12d3767ba4c84c32150cbe6ff6494498780f12c9
Bug-Debian: https://bugs.debian.org/851734
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1668093
Last-Update: 2017-03-09
Patch-Name: ssh-keygen-hash-corruption.patch
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r-- | ssh-keygen.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c index 2a7939bfc..0833ee61d 100644 --- a/ssh-keygen.c +++ b/ssh-keygen.c | |||
@@ -1082,6 +1082,7 @@ known_hosts_hash(struct hostkey_foreach_line *l, void *_ctx) | |||
1082 | struct known_hosts_ctx *ctx = (struct known_hosts_ctx *)_ctx; | 1082 | struct known_hosts_ctx *ctx = (struct known_hosts_ctx *)_ctx; |
1083 | char *hashed, *cp, *hosts, *ohosts; | 1083 | char *hashed, *cp, *hosts, *ohosts; |
1084 | int has_wild = l->hosts && strcspn(l->hosts, "*?!") != strlen(l->hosts); | 1084 | int has_wild = l->hosts && strcspn(l->hosts, "*?!") != strlen(l->hosts); |
1085 | int was_hashed = l->hosts[0] == HASH_DELIM; | ||
1085 | 1086 | ||
1086 | switch (l->status) { | 1087 | switch (l->status) { |
1087 | case HKF_STATUS_OK: | 1088 | case HKF_STATUS_OK: |
@@ -1090,8 +1091,7 @@ known_hosts_hash(struct hostkey_foreach_line *l, void *_ctx) | |||
1090 | * Don't hash hosts already already hashed, with wildcard | 1091 | * Don't hash hosts already already hashed, with wildcard |
1091 | * characters or a CA/revocation marker. | 1092 | * characters or a CA/revocation marker. |
1092 | */ | 1093 | */ |
1093 | if ((l->match & HKF_MATCH_HOST_HASHED) != 0 || | 1094 | if (was_hashed || has_wild || l->marker != MRK_NONE) { |
1094 | has_wild || l->marker != MRK_NONE) { | ||
1095 | fprintf(ctx->out, "%s\n", l->line); | 1095 | fprintf(ctx->out, "%s\n", l->line); |
1096 | if (has_wild && !find_host) { | 1096 | if (has_wild && !find_host) { |
1097 | logit("%s:%ld: ignoring host name " | 1097 | logit("%s:%ld: ignoring host name " |