summaryrefslogtreecommitdiff
path: root/java/openjdk6/files/icedtea/security/20130416/8003543.patch
blob: 8178f0b5eee6eba683afc5d61a4b20ac1f30883a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
--- /dev/null	2013-04-25 15:02:13.000000000 -0400
+++ jaxws/patches/jaxws_src/8003543.patch	2013-04-25 15:03:47.000000000 -0400
@@ -0,0 +1,224 @@
+--- src/com/sun/xml/internal/org/jvnet/mimepull/MemoryData.java
++++ src/com/sun/xml/internal/org/jvnet/mimepull/MemoryData.java
+@@ -1,5 +1,5 @@
+ /*
+- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
++ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+  *
+  * This code is free software; you can redistribute it and/or modify it
+@@ -27,6 +27,7 @@
+ import java.nio.ByteBuffer;
+ import java.io.File;
+ import java.io.IOException;
++import java.util.logging.Level;
+ import java.util.logging.Logger;
+ 
+ /**
+@@ -49,41 +50,45 @@
+     }
+ 
+     // size of the chunk given by the parser
++    @Override
+     public int size() {
+         return len;
+     }
+ 
++    @Override
+     public byte[] read() {
+         return data;
+     }
+ 
++    @Override
+     public long writeTo(DataFile file) {
+         return file.writeTo(data, 0, len);
+     }
+ 
+     /**
+-     *
+      * @param dataHead
+      * @param buf
+      * @return
+      */
++    @Override
+     public Data createNext(DataHead dataHead, ByteBuffer buf) {
+         if (!config.isOnlyMemory() && dataHead.inMemory >= config.memoryThreshold) {
+             try {
+                 String prefix = config.getTempFilePrefix();
+                 String suffix = config.getTempFileSuffix();
+-                File dir = config.getTempDir();
+-                File tempFile = (dir == null)
+-                        ? File.createTempFile(prefix, suffix)
+-                        : File.createTempFile(prefix, suffix, dir);
+-                LOGGER.fine("Created temp file = "+tempFile);
++                File tempFile = TempFiles.createTempFile(prefix, suffix, config.getTempDir());
++                // delete the temp file when VM exits as a last resort for file clean up
++                tempFile.deleteOnExit();
++                if (LOGGER.isLoggable(Level.FINE)) {
++                    LOGGER.log(Level.FINE, "Created temp file = {0}", tempFile);
++                }
+                 dataHead.dataFile = new DataFile(tempFile);
+-            } catch(IOException ioe) {
++            } catch (IOException ioe) {
+                 throw new MIMEParsingException(ioe);
+             }
+ 
+             if (dataHead.head != null) {
+-                for(Chunk c=dataHead.head; c != null; c=c.next) {
++                for (Chunk c = dataHead.head; c != null; c = c.next) {
+                     long pointer = c.data.writeTo(dataHead.dataFile);
+                     c.data = new FileData(dataHead.dataFile, pointer, len);
+                 }
+@@ -93,4 +98,5 @@
+             return new MemoryData(buf, config);
+         }
+     }
++
+ }
+--- /dev/null
++++ src/com/sun/xml/internal/org/jvnet/mimepull/TempFiles.java
+@@ -0,0 +1,144 @@
++/*
++ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ *
++ * This code is free software; you can redistribute it and/or modify it
++ * under the terms of the GNU General Public License version 2 only, as
++ * published by the Free Software Foundation.  Oracle designates this
++ * particular file as subject to the "Classpath" exception as provided
++ * by Oracle in the LICENSE file that accompanied this code.
++ *
++ * This code is distributed in the hope that it will be useful, but WITHOUT
++ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
++ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
++ * version 2 for more details (a copy is included in the LICENSE file that
++ * accompanied this code).
++ *
++ * You should have received a copy of the GNU General Public License version
++ * 2 along with this work; if not, write to the Free Software Foundation,
++ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
++ *
++ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
++ * or visit www.oracle.com if you need additional information or have any
++ * questions.
++ */
++
++package com.sun.xml.internal.org.jvnet.mimepull;
++
++import java.io.File;
++import java.io.IOException;
++import java.lang.reflect.Array;
++import java.lang.reflect.InvocationTargetException;
++import java.lang.reflect.Method;
++import java.util.logging.Level;
++import java.util.logging.Logger;
++
++/**
++ * Helper utility to support jdk <= jdk1.6. After jdk1.6 EOL reflection can be removed and API can be used directly.
++ */
++class TempFiles {
++
++    private static final Logger LOGGER = Logger.getLogger(TempFiles.class.getName());
++
++    private static final Class<?> CLASS_FILES;
++    private static final Class<?> CLASS_PATH;
++    private static final Class<?> CLASS_FILE_ATTRIBUTE;
++    private static final Class<?> CLASS_FILE_ATTRIBUTES;
++    private static final Method METHOD_FILE_TO_PATH;
++    private static final Method METHOD_FILES_CREATE_TEMP_FILE;
++    private static final Method METHOD_FILES_CREATE_TEMP_FILE_WITHPATH;
++
++    private static final Method METHOD_PATH_TO_FILE;
++
++    private static boolean useJdk6API;
++
++    static {
++        useJdk6API = isJdk6();
++
++        CLASS_FILES = safeGetClass("java.nio.file.Files");
++        CLASS_PATH = safeGetClass("java.nio.file.Path");
++        CLASS_FILE_ATTRIBUTE = safeGetClass("java.nio.file.attribute.FileAttribute");
++        CLASS_FILE_ATTRIBUTES = safeGetClass("[Ljava.nio.file.attribute.FileAttribute;");
++        METHOD_FILE_TO_PATH = safeGetMethod(File.class, "toPath");
++        METHOD_FILES_CREATE_TEMP_FILE = safeGetMethod(CLASS_FILES, "createTempFile", String.class, String.class, CLASS_FILE_ATTRIBUTES);
++        METHOD_FILES_CREATE_TEMP_FILE_WITHPATH = safeGetMethod(CLASS_FILES, "createTempFile", CLASS_PATH, String.class, String.class, CLASS_FILE_ATTRIBUTES);
++        METHOD_PATH_TO_FILE = safeGetMethod(CLASS_PATH, "toFile");
++    }
++
++    private static boolean isJdk6() {
++        String javaVersion = System.getProperty("java.version");
++        LOGGER.log(Level.FINEST, "Detected java version = {0}", javaVersion);
++        return javaVersion.startsWith("1.6.");
++    }
++
++    private static Class<?> safeGetClass(String className) {
++        // it is jdk 6 or something failed already before
++        if (useJdk6API) return null;
++        try {
++            return Class.forName(className);
++        } catch (ClassNotFoundException e) {
++            LOGGER.log(Level.SEVERE, "Exception cought", e);
++            LOGGER.log(Level.WARNING, "Class {0} not found. Temp files will be created using old java.io API.", className);
++            useJdk6API = true;
++            return null;
++        }
++    }
++
++    private static Method safeGetMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
++        // it is jdk 6 or something failed already before
++        if (useJdk6API) return null;
++        try {
++            return clazz.getMethod(methodName, parameterTypes);
++        } catch (NoSuchMethodException e) {
++            LOGGER.log(Level.SEVERE, "Exception cought", e);
++            LOGGER.log(Level.WARNING, "Method {0} not found. Temp files will be created using old java.io API.", methodName);
++            useJdk6API = true;
++            return null;
++        }
++    }
++
++
++    static Object toPath(File f) throws InvocationTargetException, IllegalAccessException {
++        return METHOD_FILE_TO_PATH.invoke(f);
++    }
++
++    static File toFile(Object path) throws InvocationTargetException, IllegalAccessException {
++        return (File) METHOD_PATH_TO_FILE.invoke(path);
++    }
++
++    static File createTempFile(String prefix, String suffix, File dir) throws IOException {
++
++        if (useJdk6API) {
++            LOGGER.log(Level.FINEST, "Jdk6 detected, temp file (prefix:{0}, suffix:{1}) being created using old java.io API.", new Object[]{prefix, suffix});
++            return File.createTempFile(prefix, suffix, dir);
++
++        } else {
++
++            try {
++                if (dir != null) {
++                    Object path = toPath(dir);
++                    LOGGER.log(Level.FINEST, "Temp file (path: {0}, prefix:{1}, suffix:{2}) being created using NIO API.", new Object[]{dir.getAbsolutePath(), prefix, suffix});
++                    return toFile(METHOD_FILES_CREATE_TEMP_FILE_WITHPATH.invoke(null, path, prefix, suffix, Array.newInstance(CLASS_FILE_ATTRIBUTE, 0)));
++                } else {
++                    LOGGER.log(Level.FINEST, "Temp file (prefix:{0}, suffix:{1}) being created using NIO API.", new Object[]{prefix, suffix});
++                    return toFile(METHOD_FILES_CREATE_TEMP_FILE.invoke(null, prefix, suffix, Array.newInstance(CLASS_FILE_ATTRIBUTE, 0)));
++                }
++
++            } catch (IllegalAccessException e) {
++                LOGGER.log(Level.SEVERE, "Exception caught", e);
++                LOGGER.log(Level.WARNING, "Error invoking java.nio API, temp file (path: {0}, prefix:{1}, suffix:{2}) being created using old java.io API.",
++                        new Object[]{dir != null ? dir.getAbsolutePath() : null, prefix, suffix});
++                return File.createTempFile(prefix, suffix, dir);
++
++            } catch (InvocationTargetException e) {
++                LOGGER.log(Level.SEVERE, "Exception caught", e);
++                LOGGER.log(Level.WARNING, "Error invoking java.nio API, temp file (path: {0}, prefix:{1}, suffix:{2}) being created using old java.io API.",
++                        new Object[]{dir != null ? dir.getAbsolutePath() : null, prefix, suffix});
++                return File.createTempFile(prefix, suffix, dir);
++            }
++        }
++
++    }
++
++
++}