Fix some memory allocation issues

master
est31 2015-09-30 01:03:38 +02:00
parent 44c909e6b4
commit a736c0c856
1 changed files with 6 additions and 5 deletions

11
srp.c
View File

@ -534,6 +534,7 @@ static int fill_buff()
for (i = 0; i < RAND_BUFF_MAX; i++) { for (i = 0; i < RAND_BUFF_MAX; i++) {
g_rand_buff[i] = srp_pcgrandom_next(r); g_rand_buff[i] = srp_pcgrandom_next(r);
} }
free(r);
} }
#endif #endif
return 1; return 1;
@ -593,6 +594,8 @@ void srp_create_salted_verification_key( SRP_HashAlgorithm alg,
if (RAND_BUFF_MAX - g_rand_idx < 16) if (RAND_BUFF_MAX - g_rand_idx < 16)
fill_buff(); fill_buff();
*bytes_s = (unsigned char*)malloc(sizeof(char) * 16); *bytes_s = (unsigned char*)malloc(sizeof(char) * 16);
if (!*bytes_s)
goto cleanup_and_exit;
memcpy(*bytes_s, &g_rand_buff + g_rand_idx, sizeof(char) * 16); memcpy(*bytes_s, &g_rand_buff + g_rand_idx, sizeof(char) * 16);
g_rand_idx += 16; g_rand_idx += 16;
} }
@ -831,7 +834,7 @@ struct SRPUser *srp_user_new(SRP_HashAlgorithm alg, SRP_NGType ng_type,
usr->password = (unsigned char*)malloc(len_password); usr->password = (unsigned char*)malloc(len_password);
usr->password_len = len_password; usr->password_len = len_password;
if (!usr->username || !usr->password) if (!usr->username || !usr->password || !usr->username_verifier)
goto err_exit; goto err_exit;
memcpy(usr->username, username, ulen); memcpy(usr->username, username, ulen);
@ -851,10 +854,8 @@ err_exit:
mpz_clear(usr->S); mpz_clear(usr->S);
if (usr->ng) if (usr->ng)
delete_ng(usr->ng); delete_ng(usr->ng);
if (usr->username) free(usr->username);
free(usr->username); free(usr->username_verifier);
if (usr->username_verifier)
free(usr->username_verifier);
if (usr->password) { if (usr->password) {
memset(usr->password, 0, usr->password_len); memset(usr->password, 0, usr->password_len);
free(usr->password); free(usr->password);