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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user