|
From: Julian S. <js...@ac...> - 2003-11-04 07:08:11
|
CVS commit by jseward:
Merge from head, all changes to do with checking staticness and
setuid/setgid flags on executables. Probably these revs:
1.37 1.36 1.35 1.34 1.32 1.31
M +41 -16 valgrind.in 1.28.2.3
--- valgrind/coregrind/valgrind.in #1.28.2.2:1.28.2.3
@@ -111,17 +111,41 @@
fi
-# Ensure the program isn't statically linked.
+# Check that the program looks ok
+is_prog=0
+
if [ $# != 0 ] ; then
- which_prog="`which $1`"
- case `file "$which_prog"` in
- *"statically linked"*)
- echo "\`$which_prog' is statically linked"
- echo "Valgrind only works on dynamically linked executables; your"
- echo "program must rely on at least one shared object for Valgrind"
- echo "to work with it. Read FAQ #5 for more information."
- exit 1 ;;
- esac
+
+ # Ensure the program exists. Ignore any error messages from 'which'.
+ which_prog=`which $1 2> /dev/null`
+ if [ z$which_prog = z ] ; then
+ echo "$0: '$1' not found in \$PATH, aborting."
+ exit
+ fi
+
+ if [ $# != 0 ] ; then
+ case `file -L "$which_prog"` in # must follow symlinks, hence -L
+ # Ensure the program isn't statically linked.
+ *"statically linked"*)
+ echo "\`$which_prog' is statically linked"
+ echo "Valgrind only works on dynamically linked executables; your"
+ echo "program must rely on at least one shared object for Valgrind"
+ echo "to work with it. Read FAQ #5 for more information."
+ exit 1 ;;
+ # Ensure that there are no setuid or gid flags
+ *:\ set?id\ ELF*)
+ echo "\`$which_prog' is suid/sgid."
+ echo "Valgrind can't handle these executables, as it"
+ echo "requires the LD_PRELOAD feature in order to work."
+ echo ""
+ echo "Remove those flags and try again."
+ echo ""
+ exit 1
+ ;;
+ esac
+ fi
+
+ is_prog=1
fi
-
+
# A bit subtle. The LD_PRELOAD added entry must be absolute
# and not depend on LD_LIBRARY_PATH. This is so that we can
@@ -140,11 +164,12 @@
#export LD_DEBUG
-# If no command given, act like -h was given so vg_main.c prints out
-# the usage string. And pass to 'exec' tha name of any program -- it doesn't
-# matter which -- because it won't be run anyway (we use 'true').
-if [ $# != 0 ] ; then
+# Actually run the program, under Valgrind's control
+if [ $is_prog = 1 ] ; then
exec "$@"
else
- VG_ARGS="$VG_ARGS -h"
+ # If no command given, act like -h was given so vg_main.c prints out the
+ # usage string. And pass to 'exec' the name of any program -- it doesn't
+ # matter which -- because it won't be run anyway (we use 'true').
+ VG_ARGS="$VG_ARGS -h"
exec true
fi
|