Bug 2103 – import expression with relative path fails on Linux
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2008-05-12T21:36:00Z
Last change time
2014-02-24T15:32:19Z
Assigned to
bugzilla
Creator
wbaxter
Comments
Comment #0 by wbaxter — 2008-05-12T21:36:42Z
This fails using dmd/dsss on Linux even when -J. is specified.
string code = import("relative/file.txt");
Assuming your main.d is in . and there exists a file ./relative/file.txt. It should look relative to the current dir but for some reason it does not work on Linux. Works fine on Windows though.
Making a symlink and importing "file.txt" instead is a workaround:
ln -s relative/file.txt ./file.txt
Comment #1 by cslush — 2009-03-24T20:20:23Z
*** Bug 2759 has been marked as a duplicate of this bug. ***
Comment #2 by bugzilla — 2009-03-25T04:55:56Z
It works on Windows because of a bug where '/' was not recognized as a directory separator.
The reason for the restriction against paths in the imports is to prevent remote execution exploits. Consider where compiling is done on a remote machine over a network. The remote machine needs to have control over what directory the import can read files from, otherwise there's a potential vector for attack.
If you need to have multiple directories, they can all be specified on the command line as a list. I'm going to mark this as invalid as it is a deliberate design choice. You can reopen it as an enhancement request if you prefer, but I'll need convincing that relative paths don't leave a hole where an attacker could potentially try to read any file in the system.
I figured it was best to be secure rather than sorry.