|
Lines 15-20
import java.io.File;
Link Here
|
| 15 |
import java.io.IOException; |
15 |
import java.io.IOException; |
| 16 |
import java.util.Enumeration; |
16 |
import java.util.Enumeration; |
| 17 |
import java.util.NoSuchElementException; |
17 |
import java.util.NoSuchElementException; |
|
|
18 |
import org.eclipse.osgi.framework.internal.core.FrameworkProperties; |
| 18 |
import org.eclipse.osgi.internal.baseadaptor.AdaptorMsg; |
19 |
import org.eclipse.osgi.internal.baseadaptor.AdaptorMsg; |
| 19 |
import org.eclipse.osgi.util.NLS; |
20 |
import org.eclipse.osgi.util.NLS; |
| 20 |
|
21 |
|
|
Lines 24-29
import org.eclipse.osgi.util.NLS;
Link Here
|
| 24 |
*/ |
25 |
*/ |
| 25 |
public class DirBundleFile extends BundleFile { |
26 |
public class DirBundleFile extends BundleFile { |
| 26 |
|
27 |
|
|
|
28 |
private static final String POINTER_SAME_DIRECTORY_1 = "/.";//$NON-NLS-1$ |
| 29 |
private static final String POINTER_SAME_DIRECTORY_2 = "//";//$NON-NLS-1$ |
| 30 |
private static final String POINTER_UPPER_DIRECTORY = "..";//$NON-NLS-1$ |
| 31 |
|
| 32 |
protected static final String PROPERTY_STRICT_BUNDLE_ENTRY_PATH = "osgi.strictBundleEntryPath";//$NON-NLS-1$ |
| 33 |
protected static final String PROPERTY_STRICT_BUNDLE_ENTRY_PATH_DEFAULT_VALUE = "false";//$NON-NLS-1$ |
| 34 |
|
| 35 |
private final String baseFileCanonicalPath; |
| 36 |
private final boolean enabledStrictBundleEntryPath; |
| 37 |
|
| 27 |
/** |
38 |
/** |
| 28 |
* Constructs a DirBundleFile |
39 |
* Constructs a DirBundleFile |
| 29 |
* @param basefile the base file |
40 |
* @param basefile the base file |
|
Lines 34-55
public class DirBundleFile extends BundleFile {
Link Here
|
| 34 |
if (!BundleFile.secureAction.exists(basefile) || !BundleFile.secureAction.isDirectory(basefile)) { |
45 |
if (!BundleFile.secureAction.exists(basefile) || !BundleFile.secureAction.isDirectory(basefile)) { |
| 35 |
throw new IOException(NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_EXCEPTION, basefile)); |
46 |
throw new IOException(NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_EXCEPTION, basefile)); |
| 36 |
} |
47 |
} |
|
|
48 |
this.baseFileCanonicalPath = BundleFile.secureAction.getCanonicalPath(basefile); |
| 49 |
this.enabledStrictBundleEntryPath = Boolean.parseBoolean(FrameworkProperties.getProperty(PROPERTY_STRICT_BUNDLE_ENTRY_PATH, PROPERTY_STRICT_BUNDLE_ENTRY_PATH_DEFAULT_VALUE)); |
| 37 |
} |
50 |
} |
| 38 |
|
51 |
|
| 39 |
public File getFile(String path, boolean nativeCode) { |
52 |
public File getFile(String path, boolean nativeCode) { |
| 40 |
boolean checkInBundle = path != null && path.indexOf("..") >= 0; //$NON-NLS-1$ |
53 |
File file = new File(this.baseFileCanonicalPath, path); |
| 41 |
File file = new File(basefile, path); |
|
|
| 42 |
if (!BundleFile.secureAction.exists(file)) { |
54 |
if (!BundleFile.secureAction.exists(file)) { |
| 43 |
return null; |
55 |
return null; |
| 44 |
} |
56 |
} |
|
|
57 |
boolean checkInBundle = false; |
| 58 |
boolean normalize = false; |
| 59 |
boolean isBundleRoot = false; |
| 60 |
if (path != null) { |
| 61 |
isBundleRoot = path.equals("/");//$NON-NLS-1$ |
| 62 |
if (!isBundleRoot) { |
| 63 |
checkInBundle = path.indexOf(POINTER_UPPER_DIRECTORY) >= 0; |
| 64 |
if (this.enabledStrictBundleEntryPath) { |
| 65 |
normalize = checkInBundle || path.indexOf(POINTER_SAME_DIRECTORY_1) >= 0 || path.indexOf(POINTER_SAME_DIRECTORY_2) >= 0; |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
File canonicalFile; |
| 70 |
try { |
| 71 |
canonicalFile = BundleFile.secureAction.getCanonicalFile(file); |
| 72 |
if (this.enabledStrictBundleEntryPath && !isBundleRoot) { |
| 73 |
File absoluteFile = BundleFile.secureAction.getAbsoluteFile(file); |
| 74 |
String canonicalPath; |
| 75 |
String absolutePath; |
| 76 |
if (normalize) { |
| 77 |
canonicalPath = canonicalFile.toURI().getPath(); |
| 78 |
absolutePath = absoluteFile.toURI().normalize().getPath(); |
| 79 |
} else { |
| 80 |
canonicalPath = canonicalFile.getPath(); |
| 81 |
absolutePath = absoluteFile.getPath(); |
| 82 |
} |
| 83 |
if (!canonicalPath.equals(absolutePath)) { |
| 84 |
return null; |
| 85 |
} |
| 86 |
} |
| 87 |
} catch (IOException e) { |
| 88 |
return null; |
| 89 |
} |
| 45 |
// must do an extra check to make sure file is within the bundle (bug 320546) |
90 |
// must do an extra check to make sure file is within the bundle (bug 320546) |
| 46 |
if (checkInBundle) { |
91 |
if (checkInBundle) { |
| 47 |
try { |
92 |
if (!canonicalFile.getPath().startsWith(this.baseFileCanonicalPath)) |
| 48 |
if (!BundleFile.secureAction.getCanonicalPath(file).startsWith(BundleFile.secureAction.getCanonicalPath(basefile))) |
|
|
| 49 |
return null; |
| 50 |
} catch (IOException e) { |
| 51 |
return null; |
93 |
return null; |
| 52 |
} |
|
|
| 53 |
} |
94 |
} |
| 54 |
return file; |
95 |
return file; |
| 55 |
} |
96 |
} |