2024-05-28 16:43:04 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2011-07-20 12:15:40 +00:00
|
|
|
# Test that users cannot register specially-crafted derivations that
|
|
|
|
# produce output paths belonging to other derivations. This could be
|
|
|
|
# used to inject malware into the store.
|
|
|
|
|
|
|
|
source common.sh
|
|
|
|
|
|
|
|
clearStore
|
|
|
|
|
|
|
|
startDaemon
|
|
|
|
|
|
|
|
# Determine the output path of the "good" derivation.
|
2011-10-10 21:32:34 +00:00
|
|
|
goodOut=$(nix-store -q $(nix-instantiate ./secure-drv-outputs.nix -A good))
|
2011-07-20 12:15:40 +00:00
|
|
|
|
|
|
|
# Instantiate the "bad" derivation.
|
2011-10-10 21:32:34 +00:00
|
|
|
badDrv=$(nix-instantiate ./secure-drv-outputs.nix -A bad)
|
|
|
|
badOut=$(nix-store -q $badDrv)
|
2011-07-20 12:15:40 +00:00
|
|
|
|
|
|
|
# Rewrite the bad derivation to produce the output path of the good
|
|
|
|
# derivation.
|
|
|
|
rm -f $TEST_ROOT/bad.drv
|
|
|
|
sed -e "s|$badOut|$goodOut|g" < $badDrv > $TEST_ROOT/bad.drv
|
|
|
|
|
|
|
|
# Add the manipulated derivation to the store and build it. This
|
|
|
|
# should fail.
|
2011-10-10 21:32:34 +00:00
|
|
|
if badDrv2=$(nix-store --add $TEST_ROOT/bad.drv); then
|
|
|
|
nix-store -r "$badDrv2"
|
2011-07-20 12:15:40 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Now build the good derivation.
|
2012-09-11 23:14:15 +00:00
|
|
|
goodOut2=$(nix-build ./secure-drv-outputs.nix -A good --no-out-link)
|
2011-07-20 12:15:40 +00:00
|
|
|
test "$goodOut" = "$goodOut2"
|
|
|
|
|
|
|
|
if ! test -e "$goodOut"/good; then
|
|
|
|
echo "Bad derivation stole the output path of the good derivation!"
|
|
|
|
exit 1
|
|
|
|
fi
|