mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
primops/import: add preflight check to parseExprFromFile
This commit is contained in:
parent
37b4407c5c
commit
65e142d193
1 changed files with 2 additions and 0 deletions
|
@ -3055,6 +3055,8 @@ Expr * EvalState::parseExprFromFile(const SourcePath & path)
|
||||||
Expr * EvalState::parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv)
|
Expr * EvalState::parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv)
|
||||||
{
|
{
|
||||||
auto buffer = path.resolveSymlinks().readFile();
|
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
|
// readFile hopefully have left some extra space for terminators
|
||||||
buffer.append("\0\0", 2);
|
buffer.append("\0\0", 2);
|
||||||
return parse(buffer.data(), buffer.size(), Pos::Origin(path), path.parent(), staticEnv);
|
return parse(buffer.data(), buffer.size(), Pos::Origin(path), path.parent(), staticEnv);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue