diff options
author | Tuomas Tynkkynen <tuomas@tuxera.com> | 2018-04-03T12·27+0300 |
---|---|---|
committer | Tuomas Tynkkynen <tuomas@tuxera.com> | 2018-04-03T12·54+0300 |
commit | af86132e1afa65b4b466af3ea9c7084836c91ee0 (patch) | |
tree | 981540a89d072525f59bfaea389bb8950859e267 | |
parent | 3fbaa230a23ef47100eb1f117008a1cee85fcf5e (diff) |
libexpr: Make unsafeGetAttrPos not crash on noPos
Currently e.g. `builtins.unsafeGetAttrPos "abort" builtins` will eventually segfault because pos->file is an unset Symbol. Found by afl-fuzz.
-rw-r--r-- | src/libexpr/eval.cc | 2 | ||||
-rw-r--r-- | tests/lang/eval-okay-getattrpos-undefined.exp | 1 | ||||
-rw-r--r-- | tests/lang/eval-okay-getattrpos-undefined.nix | 1 |
3 files changed, 3 insertions, 1 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 37b977736e28..8548990795ab 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -628,7 +628,7 @@ void EvalState::mkThunk_(Value & v, Expr * expr) void EvalState::mkPos(Value & v, Pos * pos) { - if (pos) { + if (pos && pos->file.set()) { mkAttrs(v, 3); mkString(*allocAttr(v, sFile), pos->file); mkInt(*allocAttr(v, sLine), pos->line); diff --git a/tests/lang/eval-okay-getattrpos-undefined.exp b/tests/lang/eval-okay-getattrpos-undefined.exp new file mode 100644 index 000000000000..19765bd501b6 --- /dev/null +++ b/tests/lang/eval-okay-getattrpos-undefined.exp @@ -0,0 +1 @@ +null diff --git a/tests/lang/eval-okay-getattrpos-undefined.nix b/tests/lang/eval-okay-getattrpos-undefined.nix new file mode 100644 index 000000000000..14dd38f7734c --- /dev/null +++ b/tests/lang/eval-okay-getattrpos-undefined.nix @@ -0,0 +1 @@ +builtins.unsafeGetAttrPos "abort" builtins |