readFile: Check against nul bytes

This commit is contained in:
Eelco Dolstra 2015-06-01 15:07:42 +02:00
parent feca5cb67f
commit 1c88e100e7

View file

@ -749,7 +749,10 @@ static void prim_readFile(EvalState & state, const Pos & pos, Value * * args, Va
throw EvalError(format("cannot read %1%, since path %2% is not valid, at %3%")
% path % e.path % pos);
}
mkString(v, readFile(state.checkSourcePath(path)).c_str());
string s = readFile(state.checkSourcePath(path));
if (s.find((char) 0) != string::npos)
throw Error(format("the contents of the file %1% cannot be represented as a Nix string") % path);
mkString(v, s.c_str());
}