1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 22:11:15 +02:00

primops/import: add preflight check to parseExprFromFile

This commit is contained in:
Johannes Kirschbauer 2025-06-06 12:02:44 +02:00
parent 37b4407c5c
commit 65e142d193
No known key found for this signature in database

View file

@ -3055,6 +3055,8 @@ Expr * EvalState::parseExprFromFile(const SourcePath & path)
Expr * EvalState::parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv)
{
auto buffer = path.resolveSymlinks().readFile();
if (buffer.size() == 0) throw Error("cannot import empty file '%s'", path);
// readFile hopefully have left some extra space for terminators
buffer.append("\0\0", 2);
return parse(buffer.data(), buffer.size(), Pos::Origin(path), path.parent(), staticEnv);