Bug#509055: openssh-client: ssh-keygen -R removes all comments from known_hosts file
Package: openssh-client
Version: 1:6.0p1-4
Followup-For: Bug #509055
Control: forwarded 509055 https://bugzilla.mindrot.org/show_bug.cgi?id=1545
A patch has been available for this upstream for over a year. I've
updated it so that it applies against 6.2p1.
This is a user data loss issue (any comments entered by the user into
a known_hosts file to annotate keys there will be thrown away), so i
consider it kind of a big deal.
Attached is the corrected patch, which should be able to be dropped
into debian/patches.
Thanks for maintaining ssh in debian.
Regards,
--dkg
-- System Information:
Debian Release: jessie/sid
APT prefers testing
APT policy: (500, 'testing'), (200, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 3.8-trunk-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages openssh-client depends on:
ii adduser 3.113+nmu3
ii debconf [debconf-2.0] 1.5.50
ii dpkg 1.16.10
ii libc6 2.17-2
ii libedit2 2.11-20080614-5
ii libgssapi-krb5-2 1.10.1+dfsg-5
ii libselinux1 2.1.9-5
ii libssl1.0.0 1.0.1e-2
ii passwd 1:4.1.5.1-1
ii zlib1g 1:1.2.7.dfsg-13
Versions of packages openssh-client recommends:
ii openssh-blacklist 0.4.1+nmu1
ii openssh-blacklist-extra 0.4.1+nmu1
ii xauth 1:1.0.7-1
Versions of packages openssh-client suggests:
pn keychain <none>
pn libpam-ssh <none>
ii monkeysphere 0.36~pre-1
ii ssh-askpass 1:1.2.4.1-9
-- debconf-show failed
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -965,7 +965,8 @@
}
static void
-printhost(FILE *f, const char *name, Key *public, int ca, int hash)
+printhost(FILE *f, const char *name, const char *comment, Key *public,
+ int ca, int hash)
{
if (print_fingerprint) {
enum fp_rep rep;
@@ -988,6 +989,8 @@
fprintf(f, "%s%s%s ", ca ? CA_MARKER : "", ca ? " " : "", name);
if (!key_write(public, f))
fatal("key_write failed");
+ if (comment != NULL && *comment)
+ fprintf(f, " %s", comment);
fprintf(f, "\n");
}
}
@@ -1091,7 +1094,6 @@
continue;
}
}
-
if (*cp == HASH_DELIM) {
if (find_host || delete_host) {
cp2 = host_hash(name, cp, strlen(cp));
@@ -1107,18 +1109,18 @@
"line %d type %s%s\n", name,
num, key_type(pub),
ca ? " (CA key)" : "");
- printhost(out, cp, pub, ca, 0);
+ printhost(out, cp, kp, pub, ca, 0);
}
if (delete_host) {
if (!c && !ca)
- printhost(out, cp, pub, ca, 0);
+ printhost(out, cp, kp, pub, ca, 0);
else
printf("# Host %s found: "
"line %d type %s\n", name,
num, key_type(pub));
}
} else if (hash_hosts)
- printhost(out, cp, pub, ca, 0);
+ printhost(out, cp, kp, pub, ca, 0);
} else {
if (find_host || delete_host) {
c = (match_hostname(name, cp,
@@ -1128,12 +1130,12 @@
"line %d type %s%s\n", name,
num, key_type(pub),
ca ? " (CA key)" : "");
- printhost(out, name, pub,
+ printhost(out, name, kp, pub,
ca, hash_hosts && !ca);
}
if (delete_host) {
if (!c && !ca)
- printhost(out, cp, pub, ca, 0);
+ printhost(out, cp, kp, pub, ca, 0);
else
printf("# Host %s found: "
"line %d type %s\n", name,
@@ -1147,16 +1149,19 @@
fprintf(stderr, "Warning: "
"ignoring CA key for host: "
"%.64s\n", cp2);
- printhost(out, cp2, pub, ca, 0);
+ printhost(out, cp2, kp, pub,
+ ca, 0);
} else if (strcspn(cp2, "*?!") !=
strlen(cp2)) {
fprintf(stderr, "Warning: "
"ignoring host name with "
"metacharacters: %.64s\n",
cp2);
- printhost(out, cp2, pub, ca, 0);
+ printhost(out, cp2, kp, pub,
+ ca, 0);
} else
- printhost(out, cp2, pub, ca, 1);
+ printhost(out, cp2, kp, pub,
+ ca, 1);
}
has_unhashed = 1;
}
--- a/key.c
+++ b/key.c
@@ -693,6 +693,8 @@
"actual %d", bits, BN_num_bits(ret->rsa->n));
return -1;
}
+ while (**cpp == ' ' || **cpp == '\t')
+ (*cpp)++;
success = 1;
break;
case KEY_UNSPEC:
@@ -815,6 +817,8 @@
cp++;
while (*cp != '\0' && *cp != ' ' && *cp != '\t')
cp++;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
*cpp = cp;
break;
default:
Reply to: