summaryrefslogtreecommitdiff
path: root/hostfile.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2017-03-10 04:26:06 +0000
committerDamien Miller <djm@mindrot.org>2017-03-10 15:35:39 +1100
commitdb2597207e69912f2592cd86a1de8e948a9d7ffb (patch)
treea21ec4fe01db6c7ccfcfdc52cacb9761a4693a52 /hostfile.c
parentdf9936936c695f85c1038bd706d62edf752aca4b (diff)
upstream commit
ensure hostname is lower-case before hashing it; bz#2591 reported by Griff Miller II; ok dtucker@ Upstream-ID: c3b8b93804f376bd00d859b8bcd9fc0d86b4db17
Diffstat (limited to 'hostfile.c')
-rw-r--r--hostfile.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/hostfile.c b/hostfile.c
index 4548fbab3..e23faa969 100644
--- a/hostfile.c
+++ b/hostfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hostfile.c,v 1.67 2016/09/17 18:00:27 tedu Exp $ */ 1/* $OpenBSD: hostfile.c,v 1.68 2017/03/10 04:26:06 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -419,19 +419,24 @@ write_host_entry(FILE *f, const char *host, const char *ip,
419 const struct sshkey *key, int store_hash) 419 const struct sshkey *key, int store_hash)
420{ 420{
421 int r, success = 0; 421 int r, success = 0;
422 char *hashed_host = NULL; 422 char *hashed_host = NULL, *lhost;
423
424 lhost = xstrdup(host);
425 lowercase(lhost);
423 426
424 if (store_hash) { 427 if (store_hash) {
425 if ((hashed_host = host_hash(host, NULL, 0)) == NULL) { 428 if ((hashed_host = host_hash(lhost, NULL, 0)) == NULL) {
426 error("%s: host_hash failed", __func__); 429 error("%s: host_hash failed", __func__);
430 free(lhost);
427 return 0; 431 return 0;
428 } 432 }
429 fprintf(f, "%s ", hashed_host); 433 fprintf(f, "%s ", hashed_host);
430 } else if (ip != NULL) 434 } else if (ip != NULL)
431 fprintf(f, "%s,%s ", host, ip); 435 fprintf(f, "%s,%s ", lhost, ip);
432 else 436 else {
433 fprintf(f, "%s ", host); 437 fprintf(f, "%s ", lhost);
434 438 }
439 free(lhost);
435 if ((r = sshkey_write(key, f)) == 0) 440 if ((r = sshkey_write(key, f)) == 0)
436 success = 1; 441 success = 1;
437 else 442 else