~ubuntu-branches/ubuntu/maverick/tomcat6/maverick

« back to all changes in this revision

Viewing changes to debian/patches/webapp-classloader-deadlock-fix.patch

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2010-06-28 21:41:31 UTC
  • mfrom: (2.2.15 sid)
  • Revision ID: james.westby@ubuntu.com-20100628214131-3wktukpb3lgdf83h
Tags: 6.0.26-5
* Convert patches to dep3 format.
* Backport security fix from trunk to fix CVE-2010-1157. (Closes: #587447)
* Set urgency to medium due to the security fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Index: trunk/java/org/apache/jasper/servlet/JasperLoader.java
2
 
===================================================================
3
 
--- trunk/java/org/apache/jasper/servlet/JasperLoader.java      (revision 941867)
4
 
+++ trunk/java/org/apache/jasper/servlet/JasperLoader.java      (revision 941868)
5
 
@@ -91,7 +91,7 @@
6
 
      *                                     
7
 
      * @exception ClassNotFoundException if the class was not found
8
 
      */                                    
9
 
-    public Class loadClass(final String name, boolean resolve)
10
 
+    public synchronized Class loadClass(final String name, boolean resolve)
11
 
         throws ClassNotFoundException {
12
 
 
13
 
         Class clazz = null;                
14
 
@@ -169,4 +169,4 @@
15
 
     public final PermissionCollection getPermissions(CodeSource codeSource) {
16
 
         return permissionCollection;
17
 
     }
18
 
-}
19
 
\ No newline at end of file
20
 
+}
21
 
Index: trunk/java/org/apache/catalina/loader/ResourceEntry.java
22
 
===================================================================
23
 
--- trunk/java/org/apache/catalina/loader/ResourceEntry.java    (revision 941867)
24
 
+++ trunk/java/org/apache/catalina/loader/ResourceEntry.java    (revision 941868)
25
 
@@ -47,7 +47,7 @@
26
 
     /**
27
 
      * Loaded class.
28
 
      */
29
 
-    public Class loadedClass = null;
30
 
+    public volatile Class loadedClass = null;
31
 
 
32
 
 
33
 
     /**
34
 
Index: trunk/java/org/apache/catalina/loader/WebappClassLoader.java
35
 
===================================================================
36
 
--- trunk/java/org/apache/catalina/loader/WebappClassLoader.java        (revision 941867)
37
 
+++ trunk/java/org/apache/catalina/loader/WebappClassLoader.java        (revision 941868)
38
 
@@ -1432,102 +1432,121 @@
39
 
      *
40
 
      * @exception ClassNotFoundException if the class was not found
41
 
      */
42
 
-    public Class loadClass(String name, boolean resolve)
43
 
+    public synchronized Class loadClass(String name, boolean resolve)
44
 
         throws ClassNotFoundException {
45
 
 
46
 
-        synchronized (name.intern()) {
47
 
-            if (log.isDebugEnabled())
48
 
-                log.debug("loadClass(" + name + ", " + resolve + ")");
49
 
-            Class clazz = null;
50
 
-    
51
 
-            // Log access to stopped classloader
52
 
-            if (!started) {
53
 
-                try {
54
 
-                    throw new IllegalStateException();
55
 
-                } catch (IllegalStateException e) {
56
 
-                    log.info(sm.getString("webappClassLoader.stopped", name), e);
57
 
-                }
58
 
+        if (log.isDebugEnabled())
59
 
+            log.debug("loadClass(" + name + ", " + resolve + ")");
60
 
+        Class clazz = null;
61
 
+
62
 
+        // Log access to stopped classloader
63
 
+        if (!started) {
64
 
+            try {
65
 
+                throw new IllegalStateException();
66
 
+            } catch (IllegalStateException e) {
67
 
+                log.info(sm.getString("webappClassLoader.stopped", name), e);
68
 
             }
69
 
-    
70
 
-            // (0) Check our previously loaded local class cache
71
 
-            clazz = findLoadedClass0(name);
72
 
+        }
73
 
+
74
 
+        // (0) Check our previously loaded local class cache
75
 
+        clazz = findLoadedClass0(name);
76
 
+        if (clazz != null) {
77
 
+            if (log.isDebugEnabled())
78
 
+                log.debug("  Returning class from cache");
79
 
+            if (resolve)
80
 
+                resolveClass(clazz);
81
 
+            return (clazz);
82
 
+        }
83
 
+
84
 
+        // (0.1) Check our previously loaded class cache
85
 
+        clazz = findLoadedClass(name);
86
 
+        if (clazz != null) {
87
 
+            if (log.isDebugEnabled())
88
 
+                log.debug("  Returning class from cache");
89
 
+            if (resolve)
90
 
+                resolveClass(clazz);
91
 
+            return (clazz);
92
 
+        }
93
 
+
94
 
+        // (0.2) Try loading the class with the system class loader, to prevent
95
 
+        //       the webapp from overriding J2SE classes
96
 
+        try {
97
 
+            clazz = system.loadClass(name);
98
 
             if (clazz != null) {
99
 
-                if (log.isDebugEnabled())
100
 
-                    log.debug("  Returning class from cache");
101
 
                 if (resolve)
102
 
                     resolveClass(clazz);
103
 
                 return (clazz);
104
 
             }
105
 
-    
106
 
-            // (0.1) Check our previously loaded class cache
107
 
-            clazz = findLoadedClass(name);
108
 
-            if (clazz != null) {
109
 
-                if (log.isDebugEnabled())
110
 
-                    log.debug("  Returning class from cache");
111
 
-                if (resolve)
112
 
-                    resolveClass(clazz);
113
 
-                return (clazz);
114
 
+        } catch (ClassNotFoundException e) {
115
 
+            // Ignore
116
 
+        }
117
 
+
118
 
+        // (0.5) Permission to access this class when using a SecurityManager
119
 
+        if (securityManager != null) {
120
 
+            int i = name.lastIndexOf('.');
121
 
+            if (i >= 0) {
122
 
+                try {
123
 
+                    securityManager.checkPackageAccess(name.substring(0,i));
124
 
+                } catch (SecurityException se) {
125
 
+                    String error = "Security Violation, attempt to use " +
126
 
+                        "Restricted Class: " + name;
127
 
+                    log.info(error, se);
128
 
+                    throw new ClassNotFoundException(error, se);
129
 
+                }
130
 
             }
131
 
-    
132
 
-            // (0.2) Try loading the class with the system class loader, to prevent
133
 
-            //       the webapp from overriding J2SE classes
134
 
+        }
135
 
+
136
 
+        boolean delegateLoad = delegate || filter(name);
137
 
+
138
 
+        // (1) Delegate to our parent if requested
139
 
+        if (delegateLoad) {
140
 
+            if (log.isDebugEnabled())
141
 
+                log.debug("  Delegating to parent classloader1 " + parent);
142
 
+            ClassLoader loader = parent;
143
 
+            if (loader == null)
144
 
+                loader = system;
145
 
             try {
146
 
-                clazz = system.loadClass(name);
147
 
+                clazz = loader.loadClass(name);
148
 
                 if (clazz != null) {
149
 
+                    if (log.isDebugEnabled())
150
 
+                        log.debug("  Loading class from parent");
151
 
                     if (resolve)
152
 
                         resolveClass(clazz);
153
 
                     return (clazz);
154
 
                 }
155
 
             } catch (ClassNotFoundException e) {
156
 
-                // Ignore
157
 
+                ;
158
 
             }
159
 
-    
160
 
-            // (0.5) Permission to access this class when using a SecurityManager
161
 
-            if (securityManager != null) {
162
 
-                int i = name.lastIndexOf('.');
163
 
-                if (i >= 0) {
164
 
-                    try {
165
 
-                        securityManager.checkPackageAccess(name.substring(0,i));
166
 
-                    } catch (SecurityException se) {
167
 
-                        String error = "Security Violation, attempt to use " +
168
 
-                            "Restricted Class: " + name;
169
 
-                        log.info(error, se);
170
 
-                        throw new ClassNotFoundException(error, se);
171
 
-                    }
172
 
-                }
173
 
-            }
174
 
-    
175
 
-            boolean delegateLoad = delegate || filter(name);
176
 
-    
177
 
-            // (1) Delegate to our parent if requested
178
 
-            if (delegateLoad) {
179
 
+        }
180
 
+
181
 
+        // (2) Search local repositories
182
 
+        if (log.isDebugEnabled())
183
 
+            log.debug("  Searching local repositories");
184
 
+        try {
185
 
+            clazz = findClass(name);
186
 
+            if (clazz != null) {
187
 
                 if (log.isDebugEnabled())
188
 
-                    log.debug("  Delegating to parent classloader1 " + parent);
189
 
-                ClassLoader loader = parent;
190
 
-                if (loader == null)
191
 
-                    loader = system;
192
 
-                try {
193
 
-                    clazz = loader.loadClass(name);
194
 
-                    if (clazz != null) {
195
 
-                        if (log.isDebugEnabled())
196
 
-                            log.debug("  Loading class from parent");
197
 
-                        if (resolve)
198
 
-                            resolveClass(clazz);
199
 
-                        return (clazz);
200
 
-                    }
201
 
-                } catch (ClassNotFoundException e) {
202
 
-                    ;
203
 
-                }
204
 
+                    log.debug("  Loading class from local repository");
205
 
+                if (resolve)
206
 
+                    resolveClass(clazz);
207
 
+                return (clazz);
208
 
             }
209
 
-    
210
 
-            // (2) Search local repositories
211
 
+        } catch (ClassNotFoundException e) {
212
 
+            ;
213
 
+        }
214
 
+
215
 
+        // (3) Delegate to parent unconditionally
216
 
+        if (!delegateLoad) {
217
 
             if (log.isDebugEnabled())
218
 
-                log.debug("  Searching local repositories");
219
 
+                log.debug("  Delegating to parent classloader at end: " + parent);
220
 
+            ClassLoader loader = parent;
221
 
+            if (loader == null)
222
 
+                loader = system;
223
 
             try {
224
 
-                clazz = findClass(name);
225
 
+                clazz = loader.loadClass(name);
226
 
                 if (clazz != null) {
227
 
                     if (log.isDebugEnabled())
228
 
-                        log.debug("  Loading class from local repository");
229
 
+                        log.debug("  Loading class from parent");
230
 
                     if (resolve)
231
 
                         resolveClass(clazz);
232
 
                     return (clazz);
233
 
@@ -1535,30 +1554,10 @@
234
 
             } catch (ClassNotFoundException e) {
235
 
                 ;
236
 
             }
237
 
-    
238
 
-            // (3) Delegate to parent unconditionally
239
 
-            if (!delegateLoad) {
240
 
-                if (log.isDebugEnabled())
241
 
-                    log.debug("  Delegating to parent classloader at end: " + parent);
242
 
-                ClassLoader loader = parent;
243
 
-                if (loader == null)
244
 
-                    loader = system;
245
 
-                try {
246
 
-                    clazz = loader.loadClass(name);
247
 
-                    if (clazz != null) {
248
 
-                        if (log.isDebugEnabled())
249
 
-                            log.debug("  Loading class from parent");
250
 
-                        if (resolve)
251
 
-                            resolveClass(clazz);
252
 
-                        return (clazz);
253
 
-                    }
254
 
-                } catch (ClassNotFoundException e) {
255
 
-                    ;
256
 
-                }
257
 
-            }
258
 
-    
259
 
-            throw new ClassNotFoundException(name);
260
 
         }
261
 
+
262
 
+        throw new ClassNotFoundException(name);
263
 
+
264
 
     }
265
 
 
266
 
 
267
 
@@ -2544,7 +2543,7 @@
268
 
         if (clazz != null)
269
 
             return clazz;
270
 
 
271
 
-        synchronized (name.intern()) {
272
 
+        synchronized (this) {
273
 
             clazz = entry.loadedClass;
274
 
             if (clazz != null)
275
 
                 return clazz;