about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-06-01T13·07+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-06-01T13·07+0200
commit1c88e100e776c6707caa172d4bb7c8e445d230cc (patch)
treef04de586fa1f90857040ab37a42a5711e31c377c /src/libexpr
parentfeca5cb67f9fa208a0bd3d3038c0136abbbcb9eb (diff)
readFile: Check against nul bytes
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops.cc5
1 files changed, 4 insertions, 1 deletions
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());
 }