summaryrefslogtreecommitdiff
path: root/hostfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'hostfile.c')
-rw-r--r--hostfile.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/hostfile.c b/hostfile.c
index b6f924b23..2ff4c48b4 100644
--- a/hostfile.c
+++ b/hostfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hostfile.c,v 1.50 2010/12/04 13:31:37 djm Exp $ */ 1/* $OpenBSD: hostfile.c,v 1.52 2013/07/12 00:19:58 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
@@ -64,7 +64,7 @@ struct hostkeys {
64}; 64};
65 65
66static int 66static int
67extract_salt(const char *s, u_int l, char *salt, size_t salt_len) 67extract_salt(const char *s, u_int l, u_char *salt, size_t salt_len)
68{ 68{
69 char *p, *b64salt; 69 char *p, *b64salt;
70 u_int b64len; 70 u_int b64len;
@@ -96,7 +96,7 @@ extract_salt(const char *s, u_int l, char *salt, size_t salt_len)
96 b64salt[b64len] = '\0'; 96 b64salt[b64len] = '\0';
97 97
98 ret = __b64_pton(b64salt, salt, salt_len); 98 ret = __b64_pton(b64salt, salt, salt_len);
99 xfree(b64salt); 99 free(b64salt);
100 if (ret == -1) { 100 if (ret == -1) {
101 debug2("extract_salt: salt decode error"); 101 debug2("extract_salt: salt decode error");
102 return (-1); 102 return (-1);
@@ -115,7 +115,8 @@ host_hash(const char *host, const char *name_from_hostfile, u_int src_len)
115{ 115{
116 const EVP_MD *md = EVP_sha1(); 116 const EVP_MD *md = EVP_sha1();
117 HMAC_CTX mac_ctx; 117 HMAC_CTX mac_ctx;
118 char salt[256], result[256], uu_salt[512], uu_result[512]; 118 u_char salt[256], result[256];
119 char uu_salt[512], uu_result[512];
119 static char encoded[1024]; 120 static char encoded[1024];
120 u_int i, len; 121 u_int i, len;
121 122
@@ -133,7 +134,7 @@ host_hash(const char *host, const char *name_from_hostfile, u_int src_len)
133 } 134 }
134 135
135 HMAC_Init(&mac_ctx, salt, len, md); 136 HMAC_Init(&mac_ctx, salt, len, md);
136 HMAC_Update(&mac_ctx, host, strlen(host)); 137 HMAC_Update(&mac_ctx, (u_char *)host, strlen(host));
137 HMAC_Final(&mac_ctx, result, NULL); 138 HMAC_Final(&mac_ctx, result, NULL);
138 HMAC_cleanup(&mac_ctx); 139 HMAC_cleanup(&mac_ctx);
139 140
@@ -153,7 +154,7 @@ host_hash(const char *host, const char *name_from_hostfile, u_int src_len)
153 */ 154 */
154 155
155int 156int
156hostfile_read_key(char **cpp, u_int *bitsp, Key *ret) 157hostfile_read_key(char **cpp, int *bitsp, Key *ret)
157{ 158{
158 char *cp; 159 char *cp;
159 160
@@ -170,8 +171,10 @@ hostfile_read_key(char **cpp, u_int *bitsp, Key *ret)
170 171
171 /* Return results. */ 172 /* Return results. */
172 *cpp = cp; 173 *cpp = cp;
173 if (bitsp != NULL) 174 if (bitsp != NULL) {
174 *bitsp = key_size(ret); 175 if ((*bitsp = key_size(ret)) <= 0)
176 return 0;
177 }
175 return 1; 178 return 1;
176} 179}
177 180
@@ -327,16 +330,14 @@ free_hostkeys(struct hostkeys *hostkeys)
327 u_int i; 330 u_int i;
328 331
329 for (i = 0; i < hostkeys->num_entries; i++) { 332 for (i = 0; i < hostkeys->num_entries; i++) {
330 xfree(hostkeys->entries[i].host); 333 free(hostkeys->entries[i].host);
331 xfree(hostkeys->entries[i].file); 334 free(hostkeys->entries[i].file);
332 key_free(hostkeys->entries[i].key); 335 key_free(hostkeys->entries[i].key);
333 bzero(hostkeys->entries + i, sizeof(*hostkeys->entries)); 336 bzero(hostkeys->entries + i, sizeof(*hostkeys->entries));
334 } 337 }
335 if (hostkeys->entries != NULL) 338 free(hostkeys->entries);
336 xfree(hostkeys->entries); 339 bzero(hostkeys, sizeof(*hostkeys));
337 hostkeys->entries = NULL; 340 free(hostkeys);
338 hostkeys->num_entries = 0;
339 xfree(hostkeys);
340} 341}
341 342
342static int 343static int