From 73bb8966c6417bbd11ea0490da79aba096831723 Mon Sep 17 00:00:00 2001 From: "wtc%netscape.com" Date: Tue, 21 Jan 2003 19:33:24 +0000 Subject: [PATCH] Bug 189345: we incorrectly assumed that a C_XxxFinal call to determine the length of the buffer would also terminate the active operation if the buffer length is 0. PKCS#11 says it doesn't, so we need to make the additional C_XxxFinal call even if the buffer length is 0. Allocate a buffer from the heap if the stack buffer is too small and free the heap-allocated buffer before we return from pk11_Finalize. We can use the stack buffer if count is equal to its size. git-svn-id: svn://10.0.0.236/trunk@136742 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/security/nss/lib/pk11wrap/pk11skey.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mozilla/security/nss/lib/pk11wrap/pk11skey.c b/mozilla/security/nss/lib/pk11wrap/pk11skey.c index 05ec6a6992d..3436c04807f 100644 --- a/mozilla/security/nss/lib/pk11wrap/pk11skey.c +++ b/mozilla/security/nss/lib/pk11wrap/pk11skey.c @@ -4122,6 +4122,9 @@ finalize: } if (crv != CKR_OK) { + if (buffer != stackBuf) { + PORT_Free(buffer); + } if (crv == CKR_OPERATION_NOT_INITIALIZED) { /* if there's no operation, it is finalized */ return SECSuccess; @@ -4131,13 +4134,20 @@ finalize: } /* try to finalize the session with a buffer */ - if (buffer == NULL && count > 0) { - if (count < sizeof stackBuf) { + if (buffer == NULL) { + if (count <= sizeof stackBuf) { buffer = stackBuf; - goto finalize; } else { - return SECFailure; + buffer = PORT_Alloc(count); + if (buffer == NULL) { + PORT_SetError(SEC_ERROR_NO_MEMORY); + return SECFailure; + } } + goto finalize; + } + if (buffer != stackBuf) { + PORT_Free(buffer); } return SECSuccess; }