提交 b9fd9a1c 编写于 作者: C coffeys

7024697: SessionRef.dispose() should determine if the token referred to by the...

7024697: SessionRef.dispose() should determine if the token referred to by the token object is still valid
Reviewed-by: valeriep
上级 64fbbc14
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -87,7 +87,7 @@ final class Session implements Comparable<Session> { ...@@ -87,7 +87,7 @@ final class Session implements Comparable<Session> {
} }
long id() { long id() {
if (token.isPresent(this) == false) { if (token.isPresent(this.id) == false) {
throw new ProviderException("Token has been removed"); throw new ProviderException("Token has been removed");
} }
lastAccess = System.currentTimeMillis(); lastAccess = System.currentTimeMillis();
...@@ -167,7 +167,9 @@ final class SessionRef extends PhantomReference<Session> ...@@ -167,7 +167,9 @@ final class SessionRef extends PhantomReference<Session>
void dispose() { void dispose() {
refList.remove(this); refList.remove(this);
try { try {
token.p11.C_CloseSession(id); if (token.isPresent(id)) {
token.p11.C_CloseSession(id);
}
} catch (PKCS11Exception e1) { } catch (PKCS11Exception e1) {
// ignore // ignore
} catch (ProviderException e2) { } catch (ProviderException e2) {
......
/* /*
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -217,7 +217,7 @@ class Token implements Serializable { ...@@ -217,7 +217,7 @@ class Token implements Serializable {
// return whether a token is present (i.e. token not removed) // return whether a token is present (i.e. token not removed)
// returns cached value if current, otherwise performs new check // returns cached value if current, otherwise performs new check
boolean isPresent(Session session) { boolean isPresent(long sessionID) {
if (removable == false) { if (removable == false) {
return true; return true;
} }
...@@ -238,7 +238,7 @@ class Token implements Serializable { ...@@ -238,7 +238,7 @@ class Token implements Serializable {
// the token should return an error // the token should return an error
CK_SESSION_INFO sessInfo = CK_SESSION_INFO sessInfo =
provider.p11.C_GetSessionInfo provider.p11.C_GetSessionInfo
(session.idInternal()); (sessionID);
ok = true; ok = true;
} }
} catch (PKCS11Exception e) { } catch (PKCS11Exception e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册