Mercurial > dropbear
comparison signkey.c @ 1409:c721e8c42d2a
add m_mp_free_multi, be more careful freeing when failing to load keys
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 26 May 2017 21:08:43 +0800 |
parents | 750ec4ec4cbe |
children | 798854f62430 c1c3d5943bfc |
comparison
equal
deleted
inserted
replaced
1407:8d9bad0a1c86 | 1409:c721e8c42d2a |
---|---|
165 if (keytype == DROPBEAR_SIGNKEY_DSS) { | 165 if (keytype == DROPBEAR_SIGNKEY_DSS) { |
166 dss_key_free(key->dsskey); | 166 dss_key_free(key->dsskey); |
167 key->dsskey = m_malloc(sizeof(*key->dsskey)); | 167 key->dsskey = m_malloc(sizeof(*key->dsskey)); |
168 ret = buf_get_dss_pub_key(buf, key->dsskey); | 168 ret = buf_get_dss_pub_key(buf, key->dsskey); |
169 if (ret == DROPBEAR_FAILURE) { | 169 if (ret == DROPBEAR_FAILURE) { |
170 m_free(key->dsskey); | 170 dss_key_free(key->dsskey); |
171 key->dsskey = NULL; | |
171 } | 172 } |
172 } | 173 } |
173 #endif | 174 #endif |
174 #if DROPBEAR_RSA | 175 #if DROPBEAR_RSA |
175 if (keytype == DROPBEAR_SIGNKEY_RSA) { | 176 if (keytype == DROPBEAR_SIGNKEY_RSA) { |
176 rsa_key_free(key->rsakey); | 177 rsa_key_free(key->rsakey); |
177 key->rsakey = m_malloc(sizeof(*key->rsakey)); | 178 key->rsakey = m_malloc(sizeof(*key->rsakey)); |
178 ret = buf_get_rsa_pub_key(buf, key->rsakey); | 179 ret = buf_get_rsa_pub_key(buf, key->rsakey); |
179 if (ret == DROPBEAR_FAILURE) { | 180 if (ret == DROPBEAR_FAILURE) { |
180 m_free(key->rsakey); | 181 rsa_key_free(key->rsakey); |
182 key->rsakey = NULL; | |
181 } | 183 } |
182 } | 184 } |
183 #endif | 185 #endif |
184 #if DROPBEAR_ECDSA | 186 #if DROPBEAR_ECDSA |
185 if (signkey_is_ecdsa(keytype)) { | 187 if (signkey_is_ecdsa(keytype)) { |
199 #endif | 201 #endif |
200 | 202 |
201 TRACE2(("leave buf_get_pub_key")) | 203 TRACE2(("leave buf_get_pub_key")) |
202 | 204 |
203 return ret; | 205 return ret; |
204 | |
205 } | 206 } |
206 | 207 |
207 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail. | 208 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail. |
208 * type should be set by the caller to specify the type to read, and | 209 * type should be set by the caller to specify the type to read, and |
209 * on return is set to the type read (useful when type = _ANY) */ | 210 * on return is set to the type read (useful when type = _ANY) */ |
234 if (keytype == DROPBEAR_SIGNKEY_DSS) { | 235 if (keytype == DROPBEAR_SIGNKEY_DSS) { |
235 dss_key_free(key->dsskey); | 236 dss_key_free(key->dsskey); |
236 key->dsskey = m_malloc(sizeof(*key->dsskey)); | 237 key->dsskey = m_malloc(sizeof(*key->dsskey)); |
237 ret = buf_get_dss_priv_key(buf, key->dsskey); | 238 ret = buf_get_dss_priv_key(buf, key->dsskey); |
238 if (ret == DROPBEAR_FAILURE) { | 239 if (ret == DROPBEAR_FAILURE) { |
239 m_free(key->dsskey); | 240 dss_key_free(key->dsskey); |
241 key->dsskey = NULL; | |
240 } | 242 } |
241 } | 243 } |
242 #endif | 244 #endif |
243 #if DROPBEAR_RSA | 245 #if DROPBEAR_RSA |
244 if (keytype == DROPBEAR_SIGNKEY_RSA) { | 246 if (keytype == DROPBEAR_SIGNKEY_RSA) { |
245 rsa_key_free(key->rsakey); | 247 rsa_key_free(key->rsakey); |
246 key->rsakey = m_malloc(sizeof(*key->rsakey)); | 248 key->rsakey = m_malloc(sizeof(*key->rsakey)); |
247 ret = buf_get_rsa_priv_key(buf, key->rsakey); | 249 ret = buf_get_rsa_priv_key(buf, key->rsakey); |
248 if (ret == DROPBEAR_FAILURE) { | 250 if (ret == DROPBEAR_FAILURE) { |
249 m_free(key->rsakey); | 251 rsa_key_free(key->rsakey); |
252 key->rsakey = NULL; | |
250 } | 253 } |
251 } | 254 } |
252 #endif | 255 #endif |
253 #if DROPBEAR_ECDSA | 256 #if DROPBEAR_ECDSA |
254 if (signkey_is_ecdsa(keytype)) { | 257 if (signkey_is_ecdsa(keytype)) { |