|
From: <sv...@va...> - 2008-09-12 17:10:26
|
Author: sewardj
Date: 2008-09-12 18:10:33 +0100 (Fri, 12 Sep 2008)
New Revision: 8602
Log:
Add some basic tests for detection of overruns of global and stack arrays.
Added:
branches/PTRCHECK/exp-ptrcheck/tests/globalerr.c
branches/PTRCHECK/exp-ptrcheck/tests/globalerr.stderr.exp-glibc28-amd64
branches/PTRCHECK/exp-ptrcheck/tests/globalerr.vgtest
branches/PTRCHECK/exp-ptrcheck/tests/stackerr.c
branches/PTRCHECK/exp-ptrcheck/tests/stackerr.stderr.exp-glibc28-amd64
branches/PTRCHECK/exp-ptrcheck/tests/stackerr.vgtest
Modified:
branches/PTRCHECK/exp-ptrcheck/tests/Makefile.am
Modified: branches/PTRCHECK/exp-ptrcheck/tests/Makefile.am
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/Makefile.am 2008-09-11 22:17:19 UTC (rev 8601)
+++ branches/PTRCHECK/exp-ptrcheck/tests/Makefile.am 2008-09-12 17:10:33 UTC (rev 8602)
@@ -31,6 +31,8 @@
ccc.vgtest \
ccc.stderr.exp-glibc25-x86 ccc.stderr.exp-glibc25-amd64 \
cmp.vgtest-disabled cmp.stderr.exp \
+ globalerr.vgtest globalerr.stdout.exp \
+ globalerr.stderr.exp-glibc28-amd64 \
fp.vgtest fp.stderr.exp \
hp_bounds.vgtest hp_bounds.stderr.exp \
hp_dangle.vgtest hp_dangle.stderr.exp \
@@ -52,6 +54,8 @@
realloc.vgtest \
realloc.stderr.exp-glibc25-x86 realloc.stderr.exp-glibc25-amd64 \
sh_script.vgtest-disabled sh_script.stderr.exp \
+ stackerr.vgtest stackerr.stdout.exp \
+ stackerr.stderr.exp-glibc28-amd64 \
strcpy.vgtest strcpy.stderr.exp \
strlen_bad.vgtest-disabled strlen_bad.stderr.exp \
strlen_good.vgtest-disabled strlen_good.stderr.exp \
@@ -66,8 +70,11 @@
zero.vgtest zero.stderr.exp
check_PROGRAMS = \
- add and arith base ccc cmp fp hp_bounds hp_dangle idiv imul \
+ add and arith base ccc cmp fp \
+ globalerr \
+ hp_bounds hp_dangle idiv imul \
justify mm not neg or partial pth_create pth_specific realloc \
+ stackerr \
strcpy strlen sub supp syscall tricky unaligned xor zero
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include \
@@ -83,6 +90,7 @@
base_SOURCES = base.c
cmp_SOURCES = cmp.c
fp_SOURCES = fp.c
+globalerr_SOURCE = globalerr.c
hp_bounds_SOURCES = hp_bounds.c
hp_dangle_SOURCES = hp_dangle.c
idiv_SOURCES = idiv.c
@@ -98,6 +106,7 @@
pth_specific_SOURCES = pth_specific.c
pth_specific_LDADD = -lpthread
realloc_SOURCES = realloc.c
+stackerr_SOURCES = stackerr.c
strcpy_SOURCES = strcpy.c
strlen_SOURCES = strlen.c
sub_SOURCES = sub.c
Added: branches/PTRCHECK/exp-ptrcheck/tests/globalerr.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/globalerr.c (rev 0)
+++ branches/PTRCHECK/exp-ptrcheck/tests/globalerr.c 2008-09-12 17:10:33 UTC (rev 8602)
@@ -0,0 +1,15 @@
+
+#include <stdio.h>
+
+short a[7];
+static short b[7];
+
+int main ( void )
+{
+ int i;
+ short sum;
+ for (i = 0; i < 7+1; i++) {
+ sum += a[i] * b[i];
+ }
+ return 1 & ((unsigned int)sum / 1000000);
+}
Added: branches/PTRCHECK/exp-ptrcheck/tests/globalerr.stderr.exp-glibc28-amd64
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/globalerr.stderr.exp-glibc28-amd64 (rev 0)
+++ branches/PTRCHECK/exp-ptrcheck/tests/globalerr.stderr.exp-glibc28-amd64 2008-09-12 17:10:33 UTC (rev 8602)
@@ -0,0 +1,14 @@
+
+Invalid read of size 2
+ at 0x........: main (globalerr.c:12)
+ Address 0x........ expected vs actual:
+ Expected: global array "a" in object with soname "NONE"
+ Actual: unknown
+
+Invalid read of size 2
+ at 0x........: main (globalerr.c:12)
+ Address 0x........ expected vs actual:
+ Expected: global array "b" in object with soname "NONE"
+ Actual: unknown
+
+ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Added: branches/PTRCHECK/exp-ptrcheck/tests/globalerr.vgtest
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/globalerr.vgtest (rev 0)
+++ branches/PTRCHECK/exp-ptrcheck/tests/globalerr.vgtest 2008-09-12 17:10:33 UTC (rev 8602)
@@ -0,0 +1 @@
+prog: globalerr
Added: branches/PTRCHECK/exp-ptrcheck/tests/stackerr.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/stackerr.c (rev 0)
+++ branches/PTRCHECK/exp-ptrcheck/tests/stackerr.c 2008-09-12 17:10:33 UTC (rev 8602)
@@ -0,0 +1,52 @@
+
+/* Check basic stack overflow detection.
+
+ It's difficult to get consistent behaviour across all platforms.
+ For example, x86 w/ gcc-4.3.1 gives
+
+ Expected: stack array "a" in frame 2 back from here
+ Actual: stack array "beforea" in frame 2 back from here
+
+ whereas amd64 w/ gcc-4.3.1 gives
+
+ Expected: stack array "a" in frame 2 back from here
+ Actual: unknown
+
+ This happens because on x86 the arrays are placed on the
+ stack without holes in between, but not so for amd64. I don't
+ know why.
+*/
+
+
+#include <stdio.h>
+
+__attribute__((noinline)) foo ( long* sa, int n )
+{
+ int i;
+ for (i = 0; i < n; i++)
+ sa[i] = 0;
+}
+
+__attribute__((noinline)) bar ( long* sa, int n )
+{
+ foo(sa, n);
+}
+
+int main ( void )
+{
+ int i;
+ long beforea[3];
+ long a[7];
+ long aftera[3];
+ bar(a, 7+1); /* generates error */
+ bar(a, 7+0); /* generates no error */
+ for (i = 0; i < 7+1; i++) {
+ a[i] = 0;
+ }
+ char beforebuf[8];
+ char buf[8];
+ char afterbuf[8];
+ sprintf(buf, "%d", 123456789);
+ return 1 & ((a[4] + beforea[1] + aftera[1] + beforebuf[1]
+ + buf[2] + afterbuf[3]) / 100000) ;
+}
Added: branches/PTRCHECK/exp-ptrcheck/tests/stackerr.stderr.exp-glibc28-amd64
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/stackerr.stderr.exp-glibc28-amd64 (rev 0)
+++ branches/PTRCHECK/exp-ptrcheck/tests/stackerr.stderr.exp-glibc28-amd64 2008-09-12 17:10:33 UTC (rev 8602)
@@ -0,0 +1,26 @@
+
+Invalid write of size 8
+ at 0x........: foo (stackerr.c:27)
+ by 0x........: bar (stackerr.c:32)
+ by 0x........: main (stackerr.c:41)
+ Address 0x........ expected vs actual:
+ Expected: stack array "a" in frame 2 back from here
+ Actual: unknown
+
+Invalid write of size 8
+ at 0x........: main (stackerr.c:44)
+ Address 0x........ expected vs actual:
+ Expected: stack array "a" in this frame
+ Actual: unknown
+
+Invalid write of size 1
+ at 0x........: _IO_default_xsputn (in /...libc...)
+ by 0x........: ...
+ by 0x........: ...
+ by 0x........: ...
+ by 0x........: main (stackerr.c:49)
+ Address 0x........ expected vs actual:
+ Expected: stack array "buf" in frame 4 back from here
+ Actual: unknown
+
+ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
Added: branches/PTRCHECK/exp-ptrcheck/tests/stackerr.vgtest
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/stackerr.vgtest (rev 0)
+++ branches/PTRCHECK/exp-ptrcheck/tests/stackerr.vgtest 2008-09-12 17:10:33 UTC (rev 8602)
@@ -0,0 +1 @@
+prog: stackerr
|