Files
libfaketime/test/syscalltest.sh
Daniel Kahn Gillmor 811283e683 Intercept syscall
This is an attempt at an implementation to address #301.

Some things worth noting:

 - I am not particularly confident in my reverse of the variadic C
   ABI. While the code appears to work for me on x86_64, I could
   imagine some variations between platforms that I'm not
   understanding.

 - This works to intercept the invocation of syscall as seen in
   test/syscalltest.sh, as long as it was compiled with -DFAKE_RANDOM

 - defining -DINTERCEPT_SYSCALL on non-Linux platforms should result
   in a compile-time error.

 - This does *not* work to intercept the syscall sent by `openssl
   rand`, for some reason I don't yet understand.  Perhaps openssl has
   some platform-specific syscall mechanism that doesn't route them
   through libc's syscall() shim?
2021-02-24 14:45:38 -05:00

30 lines
957 B
Bash
Executable File

#!/bin/sh
FTPL="${FAKETIME_TESTLIB:-../src/libfaketime.so.1}"
set -e
error=0
run0=$(./syscall_test)
run1=$(LD_PRELOAD="$FTPL" ./syscall_test)
run2=$(FAKERANDOM_SEED=0x0000000000000000 LD_PRELOAD="$FTPL" ./syscall_test)
run3=$(FAKERANDOM_SEED=0x0000000000000000 LD_PRELOAD="$FTPL" ./syscall_test)
run4=$(FAKERANDOM_SEED=0xDEADBEEFDEADBEEF LD_PRELOAD="$FTPL" ./syscall_test)
if [ "$run0" = "$run1" ] ; then
error=1
printf >&2 'test run without LD_PRELOAD matches run with LD_PRELOAD. This is very unlikely.\n'
fi
if [ "$run1" = "$run2" ] ; then
error=2
printf >&2 'test with LD_PRELOAD but without FAKERANDOM_SEED matches run with LD_PRELOAD and FAKERANDOM_SEED. This is also very unlikely.\n'
fi
if [ "$run2" != "$run3" ]; then
error=1
printf >&2 'test run with same seed produces different outputs.\n'
fi
if [ "$run3" = "$run4" ]; then
error=1
printf >&2 'test runs with different seeds produce the same outputs.\n'
fi