~ubuntu-branches/ubuntu/jaunty/clamav/jaunty-security

« back to all changes in this revision

Viewing changes to unit_tests/valgrind_tests.sh

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-04-06 14:21:16 UTC
  • mfrom: (0.35.9 sid)
  • Revision ID: james.westby@ubuntu.com-20100406142116-9jwi9mqh3mdvi8mq
Tags: 0.95.3+dfsg-1ubuntu0.09.04.1
* SECURITY UPDATE: (LP: #553266)
* References clamav bugs #1771 and #1826
* libclamav/mspack.c: fix Quantum decompressor (bb#1771)
  - clamav git 224fee54dd6cd8933d7007331ec2bfca0398d4b4
* libclamav/mspack.c: improve unpacking of malformed cabinets (bb#1826)
  - clamav git 31b77b3fb589ab07e7b4d84f8b3825178864ee51
* based on work by Scott Kitterman

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
3
 
# We don't look for 'still reachable' blocks, since clamd fork()s after loading
4
 
# the DB. The parent exits without freeing the memory (but they are freed
5
 
# anyway due to the exit).
6
 
# To test for DB load leaks, we issue a RELOAD command, which should cause
7
 
# leaks to be reported by valgrind if there are any.
8
 
9
 
 
10
 
test "x$VG" = "x1" || { echo "*** valgrind tests skipped by default, use 'make check VG=1' to activate"; exit 77; }
11
 
VALGRIND=`which ${VALGRIND-valgrind}`
12
 
test -n "$VALGRIND" || { echo "*** valgrind not found, skipping test"; exit 77; }
13
 
test -x "$VALGRIND" || { echo "*** valgrind not executable, skipping test"; exit 77; }
14
 
 
15
 
parse_valgrindlog()
16
 
{
17
 
        if test ! -f $1; then
18
 
                echo "*** Logfile $1 not found. Valgrind failed to run?"
19
 
        fi
20
 
        NRUNS=`grep "ERROR SUMMARY" $1 | wc -l`
21
 
        if test $NRUNS -eq `grep "ERROR SUMMARY: 0 errors" $1 | wc -l` && test `grep "FATAL:" $1|wc -l ` -eq 0; then
22
 
                if test "$1" = "valgrind-race.log" || 
23
 
                        test $NRUNS -eq `grep "no leaks are possible" $1 | wc -l` ||
24
 
                        test `grep "lost:" $1 | grep -v "0 bytes" | wc -l` -eq 0; then 
25
 
                        if test -z "$GENSUPP"; then
26
 
                                rm -f $1;
27
 
                        fi
28
 
                        return
29
 
                else
30
 
                        echo "*** Valgrind test FAILED, memory LEAKS detected ***"
31
 
                        grep "lost:" $1 | grep -v "0 bytes"
32
 
                fi
33
 
        else
34
 
                if test "$1" = "valgrind-race.log" ; then
35
 
                        echo "*** Valgrind test FAILED, DATA RACES detected ****"
36
 
                else
37
 
                        echo "*** Valgrind test FAILED, memory ERRORS detected ****"
38
 
                fi
39
 
                grep "ERROR SUMMARY" $1 | grep -v "0 errors"
40
 
                sed -rn '
41
 
                        /^[=0-9]+ +at/ {
42
 
                                # save current line in hold buffer
43
 
                                x
44
 
                                # print hold buffer
45
 
                                p
46
 
                                # get original line back and print
47
 
                                x
48
 
                                p
49
 
                        }
50
 
                        # store it in hold buffer
51
 
                        h
52
 
                ' <$1 | grep -Ev "Thread.+was created" | grep -v "Open"
53
 
        fi
54
 
        echo "***"
55
 
        echo "*** Please submit $1 to http://bugs.clamav.net"
56
 
        echo "***"
57
 
}
58
 
 
59
 
if test "X$VALGRIND_GENSUPP" = "X1"; then
60
 
        GENSUPP="--gen-suppressions=all"
61
 
else
62
 
        GENSUPP=
63
 
fi
64
 
 
65
 
VALGRIND_COMMON_FLAGS="-v --trace-children=yes --suppressions=$abs_srcdir/valgrind.supp $GENSUPP"
66
 
VALGRIND_FLAGS="$VALGRIND_COMMON_FLAGS --track-fds=yes --leak-check=full"
67
 
VALGRIND_FLAGS_RACE="$VALGRIND_COMMON_FLAGS --tool=helgrind"
68
 
export CK_DEFAULT_TIMEOUT=40
69
 
echo "--- Starting check_clamav under valgrind/memcheck"
70
 
rm -f valgrind-check.log valgrind-clamd.log valgrind-race.log
71
 
CK_FORK=no ../libtool --mode=execute $VALGRIND $VALGRIND_FLAGS ./check_clamav >valgrind-check.log 2>&1 &
72
 
pid1=$!
73
 
 
74
 
echo "--- Starting clamd under valgrind/memcheck"
75
 
CLAMD_WRAPPER="$VALGRIND $VALGRIND_FLAGS" $abs_srcdir/check_clamd.sh >valgrind-clamd.log 2>&1 &
76
 
pid2=$!
77
 
 
78
 
echo "--- Starting clamd under valgrind/helgrind"
79
 
CLAMD_TEST_UNIQ1=3 CLAMD_TEST_UNIQ2=4 CLAMD_WRAPPER="$VALGRIND $VALGRIND_FLAGS_RACE" $abs_srcdir/check_clamd.sh >valgrind-race.log 2>&1 &
80
 
pid3=$!
81
 
 
82
 
wait $pid1 $pid2 $pid3
83
 
parse_valgrindlog valgrind-check.log
84
 
parse_valgrindlog valgrind-clamd.log
85
 
parse_valgrindlog valgrind-race.log
86
 
 
87
 
if test -f valgrind-check.log || test -f valgrind-race.log || test -f valgrind-clamd.log; then
88
 
        exit 1;
89
 
fi
90
 
exit 0