Skip to content

Commit 5bde779

Browse files
committed
Check output of mpz_set_str and fix leak on error condition
Also add static identifier as upstream did
1 parent aab7c83 commit 5bde779

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/util/sha256.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
const char SHA256_version[] = "SHA-256" OPENSSL_VERSION_PTEXT;
1616

1717
/* mem_clr.c */
18-
unsigned char cleanse_ctr = 0;
19-
void OPENSSL_cleanse(void *ptr, size_t len)
18+
unsigned static char cleanse_ctr = 0;
19+
static void OPENSSL_cleanse(void *ptr, size_t len)
2020
{
2121
unsigned char *p = ptr;
2222
size_t loop = len, ctr = cleanse_ctr;

src/util/srp.cpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ static struct NGHex global_Ng_constants[] = {
166166
};
167167

168168

169+
static void delete_ng(NGConstant *ng)
170+
{
171+
if (ng) {
172+
mpz_clear(ng->N);
173+
mpz_clear(ng->g);
174+
free(ng);
175+
}
176+
}
177+
169178
static NGConstant *new_ng( SRP_NGType ng_type, const char *n_hex, const char *g_hex )
170179
{
171180
NGConstant *ng = (NGConstant *) malloc(sizeof(NGConstant));
@@ -180,21 +189,17 @@ static NGConstant *new_ng( SRP_NGType ng_type, const char *n_hex, const char *g_
180189
g_hex = global_Ng_constants[ ng_type ].g_hex;
181190
}
182191

183-
mpz_set_str(ng->N, n_hex, 16);
184-
mpz_set_str(ng->g, g_hex, 16);
185-
186-
return ng;
187-
}
192+
int rv = 0;
193+
rv = mpz_set_str(ng->N, n_hex, 16);
194+
rv = rv | mpz_set_str(ng->g, g_hex, 16);
188195

189-
static void delete_ng( NGConstant *ng )
190-
{
191-
if (ng) {
192-
mpz_clear(ng->N);
193-
mpz_clear(ng->g);
194-
free(ng);
196+
if (rv) {
197+
delete_ng(ng);
198+
return 0;
195199
}
196-
}
197200

201+
return ng;
202+
}
198203

199204

200205
typedef union
@@ -849,6 +854,8 @@ struct SRPUser *srp_user_new(SRP_HashAlgorithm alg, SRP_NGType ng_type,
849854
mpz_clear(usr->a);
850855
mpz_clear(usr->A);
851856
mpz_clear(usr->S);
857+
if (usr->ng)
858+
delete_ng(usr->ng);
852859
if (usr->username)
853860
free(usr->username);
854861
if (usr->username_verifier)

0 commit comments

Comments
 (0)