Skip to content

Commit f8fc0c9

Browse files
fix for memory leak and windows build issues
1 parent 341efb4 commit f8fc0c9

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/ssh.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,7 @@ int wolfSSH_CTX_UsePrivateKey_fromStore(WOLFSSH_CTX* ctx,
25132513
heap = ctx->heap;
25142514

25152515
/* Open the certificate store */
2516-
hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM_W, 0, NULL,
2516+
hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM_W, 0, (HCRYPTPROV_LEGACY)0,
25172517
dwFlags | CERT_STORE_OPEN_EXISTING_FLAG, storeName);
25182518
if (hStore == NULL) {
25192519
DWORD dwErr = GetLastError();
@@ -2639,7 +2639,7 @@ int wolfSSH_CTX_UsePrivateKey_fromStore(WOLFSSH_CTX* ctx,
26392639
/* Set up the private key structure */
26402640
ctx->privateKey[keyIdx].publicKeyFmt = keyId;
26412641
ctx->privateKey[keyIdx].useCertStore = 1;
2642-
ctx->privateKey[keyIdx].certStoreContext = pCertContext;
2642+
ctx->privateKey[keyIdx].certStoreContext = (void*)pCertContext;
26432643

26442644
/* Store the store name and subject name */
26452645
{
@@ -2657,8 +2657,8 @@ int wolfSSH_CTX_UsePrivateKey_fromStore(WOLFSSH_CTX* ctx,
26572657
return WS_MEMORY_E;
26582658
}
26592659

2660-
wcscpy(storeNameCopy, storeName);
2661-
wcscpy(subjectNameCopy, subjectName);
2660+
WMEMCPY(storeNameCopy, storeName, storeNameLen * sizeof(wchar_t));
2661+
WMEMCPY(subjectNameCopy, subjectName, subjectNameLen * sizeof(wchar_t));
26622662
ctx->privateKey[keyIdx].storeName = storeNameCopy;
26632663
ctx->privateKey[keyIdx].subjectName = subjectNameCopy;
26642664
ctx->privateKey[keyIdx].dwFlags = dwFlags;
@@ -2703,6 +2703,7 @@ int wolfSSH_CTX_UsePrivateKey_fromStore(WOLFSSH_CTX* ctx,
27032703
WFREE((void*)ctx->privateKey[keyIdx].subjectName, heap, DYNTYPE_STRING);
27042704
WFREE(ctx->privateKey[keyIdx].cert, heap, DYNTYPE_CERT);
27052705
ctx->privateKey[keyIdx].useCertStore = 0;
2706+
CertFreeCertificateContext(pCertContext);
27062707
ctx->privateKey[keyIdx].certStoreContext = NULL;
27072708
ctx->privateKey[keyIdx].storeName = NULL;
27082709
ctx->privateKey[keyIdx].subjectName = NULL;

wolfssh/internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,6 @@ WOLFSSH_LOCAL void ChannelDelete(WOLFSSH_CHANNEL*, void*);
10091009
WOLFSSH_LOCAL WOLFSSH_CHANNEL* ChannelFind(WOLFSSH*, word32, byte);
10101010
WOLFSSH_LOCAL int ChannelRemove(WOLFSSH*, word32, byte);
10111011
WOLFSSH_LOCAL int ChannelPutData(WOLFSSH_CHANNEL*, byte*, word32);
1012-
WOLFSSH_LOCAL int IdentifyAsn1Key(const byte* in, word32 inSz,
1013-
int isPrivate, void* heap);
10141012
WOLFSSH_LOCAL int IdentifyOpenSshKey(const byte* in, word32 inSz, void* heap);
10151013
WOLFSSH_LOCAL void RefreshPublicKeyAlgo(WOLFSSH_CTX* ctx);
10161014
WOLFSSH_LOCAL int wolfSSH_ProcessBuffer(WOLFSSH_CTX*,

0 commit comments

Comments
 (0)