Skip to content

Commit 64867cf

Browse files
Add wc_HashFree() to release the resource
1 parent 5be43b6 commit 64867cf

1 file changed

Lines changed: 32 additions & 25 deletions

File tree

src/internal.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14090,10 +14090,12 @@ static int BuildUserAuthRequestRsa(WOLFSSH* ssh,
1409014090
if (ret == WS_SUCCESS) {
1409114091
WMEMSET(digest, 0, sizeof(digest));
1409214092
ret = wc_HashInit(&hash, hashId);
14093-
if (ret == WS_SUCCESS)
14093+
if (ret == WS_SUCCESS) {
1409414094
ret = HashUpdate(&hash, hashId, checkData, checkDataSz);
14095-
if (ret == WS_SUCCESS)
14096-
ret = wc_HashFinal(&hash, hashId, digest);
14095+
if (ret == WS_SUCCESS)
14096+
ret = wc_HashFinal(&hash, hashId, digest);
14097+
wc_HashFree(&hash, hashId);
14098+
}
1409714099
}
1409814100

1409914101
if (ret == WS_SUCCESS) {
@@ -14324,11 +14326,12 @@ static int BuildUserAuthRequestRsaCert(WOLFSSH* ssh,
1432414326

1432514327
WMEMSET(digest, 0, sizeof(digest));
1432614328
ret = wc_HashInit(&hash, hashId);
14327-
if (ret == WS_SUCCESS)
14329+
if (ret == WS_SUCCESS) {
1432814330
ret = HashUpdate(&hash, hashId, checkData, checkDataSz);
14329-
if (ret == WS_SUCCESS)
14330-
ret = wc_HashFinal(&hash, hashId, digest);
14331-
14331+
if (ret == WS_SUCCESS)
14332+
ret = wc_HashFinal(&hash, hashId, digest);
14333+
wc_HashFree(&hash, hashId);
14334+
}
1433214335
if (ret == WS_SUCCESS) {
1433314336
c32toa(keySig->sigSz + 7 + LENGTH_SZ * 2, output + begin);
1433414337
begin += LENGTH_SZ;
@@ -14547,16 +14550,18 @@ static int BuildUserAuthRequestEcc(WOLFSSH* ssh,
1454714550
if (ret == WS_SUCCESS) {
1454814551
WLOG(WS_LOG_INFO, "Signing hash with ECDSA.");
1454914552
ret = wc_HashInit(&hash, hashId);
14550-
if (ret == WS_SUCCESS)
14553+
if (ret == WS_SUCCESS) {
1455114554
ret = HashUpdate(&hash, hashId, checkData, checkDataSz);
14552-
if (ret == WS_SUCCESS)
14553-
ret = wc_HashFinal(&hash, hashId, digest);
14554-
if (ret == WS_SUCCESS)
14555-
ret = wc_ecc_sign_hash(digest, digestSz, sig_ptr, &sigSz,
14556-
ssh->rng, &keySig->ks.ecc.key);
14557-
if (ret != WS_SUCCESS) {
14558-
WLOG(WS_LOG_DEBUG, "SUAR: Bad ECC Sign");
14559-
ret = WS_ECC_E;
14555+
if (ret == WS_SUCCESS)
14556+
ret = wc_HashFinal(&hash, hashId, digest);
14557+
if (ret == WS_SUCCESS)
14558+
ret = wc_ecc_sign_hash(digest, digestSz, sig_ptr, &sigSz,
14559+
ssh->rng, &keySig->ks.ecc.key);
14560+
if (ret != WS_SUCCESS) {
14561+
WLOG(WS_LOG_DEBUG, "SUAR: Bad ECC Sign");
14562+
ret = WS_ECC_E;
14563+
}
14564+
wc_HashFree(&hash, hashId);
1456014565
}
1456114566
}
1456214567

@@ -14787,16 +14792,18 @@ static int BuildUserAuthRequestEccCert(WOLFSSH* ssh,
1478714792
if (ret == WS_SUCCESS) {
1478814793
WLOG(WS_LOG_INFO, "Signing hash with ECDSA cert.");
1478914794
ret = wc_HashInit(&hash, hashId);
14790-
if (ret == WS_SUCCESS)
14795+
if (ret == WS_SUCCESS) {
1479114796
ret = HashUpdate(&hash, hashId, checkData, checkDataSz);
14792-
if (ret == WS_SUCCESS)
14793-
ret = wc_HashFinal(&hash, hashId, digest);
14794-
if (ret == WS_SUCCESS)
14795-
ret = wc_ecc_sign_hash(digest, digestSz, sig, &sigSz,
14796-
ssh->rng, &keySig->ks.ecc.key);
14797-
if (ret != WS_SUCCESS) {
14798-
WLOG(WS_LOG_DEBUG, "SUAR: Bad ECC Cert Sign");
14799-
ret = WS_ECC_E;
14797+
if (ret == WS_SUCCESS)
14798+
ret = wc_HashFinal(&hash, hashId, digest);
14799+
if (ret == WS_SUCCESS)
14800+
ret = wc_ecc_sign_hash(digest, digestSz, sig, &sigSz,
14801+
ssh->rng, &keySig->ks.ecc.key);
14802+
if (ret != WS_SUCCESS) {
14803+
WLOG(WS_LOG_DEBUG, "SUAR: Bad ECC Cert Sign");
14804+
ret = WS_ECC_E;
14805+
}
14806+
wc_HashFree(&hash, hashId);
1480014807
}
1480114808
}
1480214809

0 commit comments

Comments
 (0)