Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdruppe committed Sep 22, 2024
1 parent 22efb59 commit 315c29f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
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

0 comments on commit 315c29f

Please sign in to comment.