Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #75

Closed
wants to merge 1 commit into from
Closed

wip #75

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actions/5-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ runs:
if [[ '${{ runner.os }}' == Windows ]]; then
echo -e '[Environment64]\nDFLAGS=-I%@P%/../import ucrtbase.lib\nLIB=%@P%/../lib;%@P%/../lib/mingw' > install/bin/dmd.conf
fi
if [[ '${{ runner.os }}' == macOS ]]; then
echo -e '[Environment64]\nDFLAGS=-I%@P%/../import -L-L%@P%/../lib -fPIC' > install/bin/dmd.conf
fi
cp opend/phobos/generated/*/release/64/*.a install/lib
cp -a opend/phobos/generated/*/release/64/*.so* install/lib
cp -a opend/phobos/generated/*/release/64/*.dylib* install/lib
Expand Down
46 changes: 28 additions & 18 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -7593,11 +7593,6 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
se = se.toUTF8(sc);

auto namez = se.toStringz();
if (!global.filePath)
{
error(e.loc, "need `-J` switch to import text file `%s`", namez.ptr);
return setError();
}

/* Be wary of CWE-22: Improper Limitation of a Pathname to a Restricted Directory
* ('Path Traversal') attacks.
Expand All @@ -7624,19 +7619,34 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return setError();
}

auto resolvedNamez = FileName.searchPath(global.filePath, namez, false);
if (!resolvedNamez)
{
error(e.loc, "file `%s` cannot be found or not in a path specified with `-J`", se.toChars());
errorSupplemental(e.loc, "Path(s) searched (as provided by `-J`):");
foreach (idx, path; *global.filePath)
{
const attr = FileName.exists(path);
const(char)* err = attr == 2 ? "" :
(attr == 1 ? " (not a directory)" : " (path not found)");
errorSupplemental(e.loc, "[%llu]: `%s`%s", cast(ulong)idx, path, err);
}
return setError();
const(char)[] resolvedNamez;

auto loc = e.loc;
auto p = FileName.path(FileName.toAbsolute(loc.isValid() ? loc.filename : sc._module.srcfile.toChars()));

resolvedNamez = FileName.searchPath(p, namez, false);

if (!resolvedNamez) {
if (!global.filePath)
{
error(e.loc, "need `-J` switch to import text file `%s`", namez.ptr);
return setError();
}

resolvedNamez = FileName.searchPath(global.filePath, namez, false);
if (!resolvedNamez)
{
error(e.loc, "file `%s` cannot be found or not in a path specified with `-J`", se.toChars());
errorSupplemental(e.loc, "Path(s) searched (as provided by `-J`):");
foreach (idx, path; *global.filePath)
{
const attr = FileName.exists(path);
const(char)* err = attr == 2 ? "" :
(attr == 1 ? " (not a directory)" : " (path not found)");
errorSupplemental(e.loc, "[%llu]: `%s`%s", cast(ulong)idx, path, err);
}
return setError();
}
}

sc._module.contentImportedFiles.push(resolvedNamez.ptr);
Expand Down