rpm-build/scripts/verify-elf.in

161 lines
4.1 KiB
Plaintext
Raw Normal View History

2002-10-05 02:45:05 +04:00
#!/bin/sh -ef
2002-09-09 16:35:53 +04:00
#
# verify-elf - verify ELF objects.
#
2003-11-08 22:26:04 +03:00
# $Id$
# Copyright (C) 2002, 2003, 2004, 2006 Dmitry V. Levin <ldv@altlinux.org>
2002-09-09 16:35:53 +04:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
2003-11-09 19:47:45 +03:00
. @RPMCONFIGDIR@/functions
ValidateBuildRoot
2002-09-09 16:35:53 +04:00
2002-09-27 17:41:26 +04:00
: ${RPM_VERIFY_ELF_SKIPLIST:=}
elf_ldd='@RPMCONFIGDIR@/ldd'
2002-09-09 16:35:53 +04:00
rc=0
for f in "$@"; do
if [ ! -f "$f" ]; then
2003-11-09 19:47:45 +03:00
Info "$f: file unavailable"
2002-09-09 16:35:53 +04:00
rc=1
continue
fi
2002-12-30 02:33:01 +03:00
fname="${f#$RPM_BUILD_ROOT}"
fname="${fname#.}"
2002-09-27 17:41:26 +04:00
if [ -n "$RPM_VERIFY_ELF_SKIPLIST" ]; then
for skip in $RPM_VERIFY_ELF_SKIPLIST; do
if [ -z "${fname##$skip}" ]; then
2002-09-27 17:41:26 +04:00
continue 2
fi
done
fi
t="$(file -b "$f")"
2004-01-04 17:07:57 +03:00
[ -z "${t##ELF *}" -o -z "${t##* ELF *}" ] || continue
2002-09-09 16:35:53 +04:00
info=$(objdump -p "$f") || continue
if [ -n "$VERIFY_ELF_FHS" ]; then
if [ -z "${fname#/usr/share/*}" -o -z "${fname#/etc/*}" ]; then
Info "$f: ELF object out of allowed directory tree"
[ "$VERIFY_ELF_FHS" = relaxed ] || rc=1
fi
fi
2003-11-07 20:32:25 +03:00
if [ -n "$VERIFY_ELF_RPATH" ]; then
rpath=`printf %s "$info" |awk '{if ($1=="RPATH") print $2}'`
while [ -n "$rpath" ]; do
found=
for p in $RPM_BUILD_ROOT $RPM_BUILD_DIR $RPM_SOURCE_DIR; do
if printf %s "$rpath" |fgrep -qs "$p"; then
2003-11-09 19:47:45 +03:00
Info "$f: RPATH entry contains \"$p\": $rpath"
2003-11-07 20:32:25 +03:00
found=1
fi
done
if [ -n "$found" ]; then
2002-09-09 16:35:53 +04:00
rc=1
2003-11-07 20:32:25 +03:00
break
fi
if printf %s "$rpath" |fgrep -qs :; then
2003-11-09 19:47:45 +03:00
Info "$f: RPATH entry contains \":\": $rpath"
2003-11-07 20:32:25 +03:00
[ "$VERIFY_ELF_RPATH" = relaxed ] || rc=1
break
fi
if [ "$VERIFY_ELF_RPATH" = relaxed -o "$VERIFY_ELF_RPATH" = normal ]; then
break
2002-09-09 16:35:53 +04:00
fi
2003-11-09 19:47:45 +03:00
Info "$f: RPATH entry found: $rpath"
2002-09-09 16:35:53 +04:00
rc=1
2003-11-07 20:32:25 +03:00
break
done
fi
2002-09-09 16:35:53 +04:00
2003-11-07 20:32:25 +03:00
if [ -n "$VERIFY_ELF_TEXTREL" ]; then
textrel=`printf %s "$info" |awk '{if ($1=="TEXTREL") print $2}'`
while [ -n "$textrel" ]; do
Info "$f: TEXTREL entry found: $textrel"
[ "$VERIFY_ELF_TEXTREL" != relaxed ] || break
rc=1
break
done
fi
if [ -n "$VERIFY_ELF_UNRESOLVED" ]; then
while [ -z "${t##*ELF* executable*dynamically linked*}" -o -z "${t##*ELF* shared object*}" ]; do
rpath="$(printf %s "$dump" |awk '{if ($1=="RPATH") print $2}' |tr -s : ' ' |sed -e "s|\$ORIGIN|${fname%/*}|g")"
if [ -n "$rpath" ]; then
rpath="$rpath $RPM_VERIFY_ELF_LDD_RPATH"
else
rpath="$RPM_VERIFY_ELF_LDD_RPATH"
fi
rpath="$(printf %s "$rpath" |
tr -s '[:space:]' '\n' |
grep -v '^$' |
LANG=C uniq |
sed -e "s|^|$RPM_BUILD_ROOT&|" |
tr -s '[:space:]' : |
sed -e 's/^:\+//; s/:\+$//')"
if ! ldd_info="$("$elf_ldd" --undefined -- "$f" "$RPM_VERIFY_ELF_LDD_RPATH" 2>&1)"; then
printf >&2 '%s\n' "$ldd_info"
rc=1
2003-11-07 20:32:25 +03:00
break
fi
[ "$VERIFY_ELF_UNRESOLVED" = relaxed ] && ldd_rc=0 || ldd_rc=1
printf '%s\n' "$ldd_info" |
awk -vrc="$ldd_rc" -vprog="$PROG" -vfname="$f" -- '
BEGIN {
if (rc == "0")
prefix="WARNING"
else
prefix="ERROR"
errors=0
}
$2 == "=>" && $3 == "not" && $4 == "found" {
lib=$1
printf ("%s: %s: %s: not found: %s\n", prog, prefix, fname, lib)
errors=1
}
$1 == "undefined" && $2 == "symbol:" {
sym=$3
lib=$4
sub("^[(]", "", lib)
sub("[)]$", "", lib)
if (lib == fname) {
printf ("%s: %s: %s: undefined symbol: %s\n", prog, prefix, fname, sym)
errors=1
}
}
END {
if (rc != "0" && errors != 0)
exit 1
}
' && ldd_rc=0 || ldd_rc=1
[ "$VERIFY_ELF_UNRESOLVED" = relaxed -o "$ldd_rc" = 0 ] || rc=1
2003-11-07 20:32:25 +03:00
break
done
2002-09-09 16:35:53 +04:00
fi
2002-09-09 16:35:53 +04:00
done
exit $rc