mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8203182: Release session if initialization of SunPKCS11 Signature fails
Ensure session is properly released in P11Signature class Reviewed-by: valeriep
This commit is contained in:
parent
f03c183e28
commit
62c97f695f
1 changed files with 46 additions and 36 deletions
|
@ -283,6 +283,7 @@ final class P11Signature extends SignatureSpi {
|
||||||
session = token.killSession(session);
|
session = token.killSession(session);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
// "cancel" operation by finishing it
|
// "cancel" operation by finishing it
|
||||||
// XXX make sure all this always works correctly
|
// XXX make sure all this always works correctly
|
||||||
if (mode == M_SIGN) {
|
if (mode == M_SIGN) {
|
||||||
|
@ -325,6 +326,9 @@ final class P11Signature extends SignatureSpi {
|
||||||
// XXX check error code
|
// XXX check error code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
session = token.releaseSession(session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// assumes current state is initialized == false
|
// assumes current state is initialized == false
|
||||||
|
@ -342,6 +346,8 @@ final class P11Signature extends SignatureSpi {
|
||||||
}
|
}
|
||||||
initialized = true;
|
initialized = true;
|
||||||
} catch (PKCS11Exception e) {
|
} catch (PKCS11Exception e) {
|
||||||
|
// release session when initialization failed
|
||||||
|
session = token.releaseSession(session);
|
||||||
throw new ProviderException("Initialization failed", e);
|
throw new ProviderException("Initialization failed", e);
|
||||||
}
|
}
|
||||||
if (bytesProcessed != 0) {
|
if (bytesProcessed != 0) {
|
||||||
|
@ -511,6 +517,8 @@ final class P11Signature extends SignatureSpi {
|
||||||
}
|
}
|
||||||
bytesProcessed += len;
|
bytesProcessed += len;
|
||||||
} catch (PKCS11Exception e) {
|
} catch (PKCS11Exception e) {
|
||||||
|
initialized = false;
|
||||||
|
session = token.releaseSession(session);
|
||||||
throw new ProviderException(e);
|
throw new ProviderException(e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -559,6 +567,8 @@ final class P11Signature extends SignatureSpi {
|
||||||
bytesProcessed += len;
|
bytesProcessed += len;
|
||||||
byteBuffer.position(ofs + len);
|
byteBuffer.position(ofs + len);
|
||||||
} catch (PKCS11Exception e) {
|
} catch (PKCS11Exception e) {
|
||||||
|
initialized = false;
|
||||||
|
session = token.releaseSession(session);
|
||||||
throw new ProviderException("Update failed", e);
|
throw new ProviderException("Update failed", e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue