=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/hostfile.c,v retrieving revision 1.91 retrieving revision 1.92 diff -u -r1.91 -r1.92 --- src/usr.bin/ssh/hostfile.c 2021/07/05 01:16:46 1.91 +++ src/usr.bin/ssh/hostfile.c 2021/10/02 03:17:01 1.92 @@ -1,4 +1,4 @@ -/* $OpenBSD: hostfile.c,v 1.91 2021/07/05 01:16:46 dtucker Exp $ */ +/* $OpenBSD: hostfile.c,v 1.92 2021/10/02 03:17:01 dtucker Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -116,7 +116,7 @@ struct ssh_hmac_ctx *ctx; u_char salt[256], result[256]; char uu_salt[512], uu_result[512]; - static char encoded[1024]; + char *encoded = NULL; u_int len; len = ssh_digest_bytes(SSH_DIGEST_SHA1); @@ -141,10 +141,9 @@ if (__b64_ntop(salt, len, uu_salt, sizeof(uu_salt)) == -1 || __b64_ntop(result, len, uu_result, sizeof(uu_result)) == -1) fatal_f("__b64_ntop failed"); + xasprintf(&encoded, "%s%s%c%s", HASH_MAGIC, uu_salt, HASH_DELIM, + uu_result); - snprintf(encoded, sizeof(encoded), "%s%s%c%s", HASH_MAGIC, uu_salt, - HASH_DELIM, uu_result); - return (encoded); } @@ -454,6 +453,7 @@ else { fprintf(f, "%s ", lhost); } + free(hashed_host); free(lhost); if ((r = sshkey_write(key, f)) == 0) success = 1; @@ -723,8 +723,8 @@ static int match_maybe_hashed(const char *host, const char *names, int *was_hashed) { - int hashed = *names == HASH_DELIM; - const char *hashed_host; + int hashed = *names == HASH_DELIM, ret; + char *hashed_host = NULL; size_t nlen = strlen(names); if (was_hashed != NULL) @@ -732,8 +732,10 @@ if (hashed) { if ((hashed_host = host_hash(host, names, nlen)) == NULL) return -1; - return nlen == strlen(hashed_host) && - strncmp(hashed_host, names, nlen) == 0; + ret = (nlen == strlen(hashed_host) && + strncmp(hashed_host, names, nlen) == 0); + free(hashed_host); + return ret; } return match_hostname(host, names) == 1; }