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