comparison signkey.c @ 1381:c98e242dc505 fuzz

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 616417b27f55
children 798854f62430
comparison
equal deleted inserted replaced
1380:d201105df2ed 1381:c98e242dc505
166 if (keytype == DROPBEAR_SIGNKEY_DSS) { 166 if (keytype == DROPBEAR_SIGNKEY_DSS) {
167 dss_key_free(key->dsskey); 167 dss_key_free(key->dsskey);
168 key->dsskey = m_malloc(sizeof(*key->dsskey)); 168 key->dsskey = m_malloc(sizeof(*key->dsskey));
169 ret = buf_get_dss_pub_key(buf, key->dsskey); 169 ret = buf_get_dss_pub_key(buf, key->dsskey);
170 if (ret == DROPBEAR_FAILURE) { 170 if (ret == DROPBEAR_FAILURE) {
171 m_free(key->dsskey); 171 dss_key_free(key->dsskey);
172 key->dsskey = NULL;
172 } 173 }
173 } 174 }
174 #endif 175 #endif
175 #if DROPBEAR_RSA 176 #if DROPBEAR_RSA
176 if (keytype == DROPBEAR_SIGNKEY_RSA) { 177 if (keytype == DROPBEAR_SIGNKEY_RSA) {
177 rsa_key_free(key->rsakey); 178 rsa_key_free(key->rsakey);
178 key->rsakey = m_malloc(sizeof(*key->rsakey)); 179 key->rsakey = m_malloc(sizeof(*key->rsakey));
179 ret = buf_get_rsa_pub_key(buf, key->rsakey); 180 ret = buf_get_rsa_pub_key(buf, key->rsakey);
180 if (ret == DROPBEAR_FAILURE) { 181 if (ret == DROPBEAR_FAILURE) {
181 m_free(key->rsakey); 182 rsa_key_free(key->rsakey);
183 key->rsakey = NULL;
182 } 184 }
183 } 185 }
184 #endif 186 #endif
185 #if DROPBEAR_ECDSA 187 #if DROPBEAR_ECDSA
186 if (signkey_is_ecdsa(keytype)) { 188 if (signkey_is_ecdsa(keytype)) {
200 #endif 202 #endif
201 203
202 TRACE2(("leave buf_get_pub_key")) 204 TRACE2(("leave buf_get_pub_key"))
203 205
204 return ret; 206 return ret;
205
206 } 207 }
207 208
208 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail. 209 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail.
209 * type should be set by the caller to specify the type to read, and 210 * type should be set by the caller to specify the type to read, and
210 * on return is set to the type read (useful when type = _ANY) */ 211 * on return is set to the type read (useful when type = _ANY) */
235 if (keytype == DROPBEAR_SIGNKEY_DSS) { 236 if (keytype == DROPBEAR_SIGNKEY_DSS) {
236 dss_key_free(key->dsskey); 237 dss_key_free(key->dsskey);
237 key->dsskey = m_malloc(sizeof(*key->dsskey)); 238 key->dsskey = m_malloc(sizeof(*key->dsskey));
238 ret = buf_get_dss_priv_key(buf, key->dsskey); 239 ret = buf_get_dss_priv_key(buf, key->dsskey);
239 if (ret == DROPBEAR_FAILURE) { 240 if (ret == DROPBEAR_FAILURE) {
240 m_free(key->dsskey); 241 dss_key_free(key->dsskey);
242 key->dsskey = NULL;
241 } 243 }
242 } 244 }
243 #endif 245 #endif
244 #if DROPBEAR_RSA 246 #if DROPBEAR_RSA
245 if (keytype == DROPBEAR_SIGNKEY_RSA) { 247 if (keytype == DROPBEAR_SIGNKEY_RSA) {
246 rsa_key_free(key->rsakey); 248 rsa_key_free(key->rsakey);
247 key->rsakey = m_malloc(sizeof(*key->rsakey)); 249 key->rsakey = m_malloc(sizeof(*key->rsakey));
248 ret = buf_get_rsa_priv_key(buf, key->rsakey); 250 ret = buf_get_rsa_priv_key(buf, key->rsakey);
249 if (ret == DROPBEAR_FAILURE) { 251 if (ret == DROPBEAR_FAILURE) {
250 m_free(key->rsakey); 252 rsa_key_free(key->rsakey);
253 key->rsakey = NULL;
251 } 254 }
252 } 255 }
253 #endif 256 #endif
254 #if DROPBEAR_ECDSA 257 #if DROPBEAR_ECDSA
255 if (signkey_is_ecdsa(keytype)) { 258 if (signkey_is_ecdsa(keytype)) {