From: markt Date: Wed, 8 Apr 2009 12:59:21 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46967 and make behaviour consi... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0eb8182065372cf9ad44ca6a9d42284b924aa951;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46967 and make behaviour consistent when running under a security manager. Based on a patch provided by Kirk Wolf git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@763228 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/session/ManagerBase.java b/java/org/apache/catalina/session/ManagerBase.java index 9a46d24e2..5c6785534 100644 --- a/java/org/apache/catalina/session/ManagerBase.java +++ b/java/org/apache/catalina/session/ManagerBase.java @@ -223,7 +223,11 @@ public abstract class ManagerBase implements Manager, MBeanRegistration { private class PrivilegedSetRandomFile implements PrivilegedAction{ - public DataInputStream run(){ + public PrivilegedSetRandomFile(String s) { + devRandomSource = s; + } + + public DataInputStream run(){ try { File f=new File( devRandomSource ); if( ! f.exists() ) return null; @@ -233,8 +237,18 @@ public abstract class ManagerBase implements Manager, MBeanRegistration { log.debug( "Opening " + devRandomSource ); return randomIS; } catch (IOException ex){ + log.warn("Error reading " + devRandomSource, ex); + if (randomIS != null) { + try { + randomIS.close(); + } catch (Exception e) { + log.warn("Failed to close randomIS."); + } + } + devRandomSource = null; + randomIS=null; return null; - } + } } } @@ -505,10 +519,10 @@ public abstract class ManagerBase implements Manager, MBeanRegistration { * - so use it if available. */ public void setRandomFile( String s ) { - // as a hack, you can use a static file - and genarate the same + // as a hack, you can use a static file - and generate the same // session ids ( good for strange debugging ) if (Globals.IS_SECURITY_ENABLED){ - randomIS = AccessController.doPrivileged(new PrivilegedSetRandomFile()); + randomIS = AccessController.doPrivileged(new PrivilegedSetRandomFile(s)); } else { try{ devRandomSource=s; @@ -519,12 +533,15 @@ public abstract class ManagerBase implements Manager, MBeanRegistration { if( log.isDebugEnabled() ) log.debug( "Opening " + devRandomSource ); } catch( IOException ex ) { - try { - randomIS.close(); - } catch (Exception e) { - log.warn("Failed to close randomIS."); + log.warn("Error reading " + devRandomSource, ex); + if (randomIS != null) { + try { + randomIS.close(); + } catch (Exception e) { + log.warn("Failed to close randomIS."); + } } - + devRandomSource = null; randomIS=null; } }