From 1c88e100e776c6707caa172d4bb7c8e445d230cc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 1 Jun 2015 15:07:42 +0200 Subject: readFile: Check against nul bytes --- src/libexpr/primops.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/libexpr/primops.cc') diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index fe2f1b1e0ae1..95914626f1ca 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -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()); } -- cgit 1.4.1