|
From: <sv...@va...> - 2008-09-12 22:38:18
|
Author: sewardj
Date: 2008-09-12 23:38:28 +0100 (Fri, 12 Sep 2008)
New Revision: 8607
Log:
Add a new test, real-world code, stack overrun.
Added:
branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.c
branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.stderr.exp-glibc28-amd64
branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.stdout.exp
branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.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-12 22:37:08 UTC (rev 8606)
+++ branches/PTRCHECK/exp-ptrcheck/tests/Makefile.am 2008-09-12 22:38:28 UTC (rev 8607)
@@ -26,11 +26,13 @@
and.vgtest-disabled and.stderr.exp \
arith.vgtest-disabled arith.stderr.exp \
arith_include1.c arith_include2.c \
+ bad_percentify.vgtest bad_percentify.c \
+ bad_percentify.stdout.exp bad_percentify.stderr.exp-glibc28-amd64 \
base.vgtest \
base.stderr.exp-glibc25-amd64 base.stderr.exp-glibc25-x86 \
ccc.vgtest \
ccc.stderr.exp-glibc25-x86 ccc.stderr.exp-glibc25-amd64 \
- ccc.stderr.exp-glibc27-x86 \
+ ccc.stderr.exp-glibc27-x86 ccc.stderr.exp-glibc28-amd64 \
cmp.vgtest-disabled cmp.stderr.exp \
globalerr.vgtest globalerr.stdout.exp \
globalerr.stderr.exp-glibc28-amd64 \
@@ -71,7 +73,7 @@
zero.vgtest zero.stderr.exp
check_PROGRAMS = \
- add and arith base ccc cmp fp \
+ add and arith bad_percentify base ccc cmp fp \
globalerr \
hp_bounds hp_dangle idiv imul \
justify mm not neg or partial pth_create pth_specific realloc \
@@ -88,6 +90,7 @@
add_SOURCES = add.c
and_SOURCES = and.c
arith_SOURCES = arith.c
+bad_percentify_SOURCES = bad_percentify.c
base_SOURCES = base.c
cmp_SOURCES = cmp.c
fp_SOURCES = fp.c
Added: branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.c (rev 0)
+++ branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.c 2008-09-12 22:38:28 UTC (rev 8607)
@@ -0,0 +1,109 @@
+
+/* This demonstrates a stack overrun bug that exp-ptrcheck found while
+ running Valgrind itself (self hosting). As at 12 Sept 08 this bug
+ is still in Valgrind. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+typedef unsigned long long int ULong;
+typedef unsigned int UInt;
+typedef signed int Int;
+typedef char Char;
+
+/* ---------------------------------------------------------------------
+ percentify()
+ ------------------------------------------------------------------ */
+
+/* This part excerpted from coregrind/m_libcbase.c */
+
+// Percentify n/m with d decimal places. Includes the '%' symbol at the end.
+// Right justifies in 'buf'.
+void VG_percentify(ULong n, ULong m, UInt d, Int n_buf, char buf[])
+{
+ Int i, len, space;
+ ULong p1;
+ Char fmt[32];
+
+ if (m == 0) {
+ // Have to generate the format string in order to be flexible about
+ // the width of the field.
+ sprintf(fmt, "%%-%ds", n_buf);
+ // fmt is now "%<n_buf>s" where <d> is 1,2,3...
+ sprintf(buf, fmt, "--%");
+ return;
+ }
+
+ p1 = (100*n) / m;
+
+ if (d == 0) {
+ sprintf(buf, "%lld%%", p1);
+ } else {
+ ULong p2;
+ UInt ex;
+ switch (d) {
+ case 1: ex = 10; break;
+ case 2: ex = 100; break;
+ case 3: ex = 1000; break;
+ default: assert(0);
+ /* was: VG_(tool_panic)("Currently can only handle 3 decimal places"); */
+ }
+ p2 = ((100*n*ex) / m) % ex;
+ // Have to generate the format string in order to be flexible about
+ // the width of the post-decimal-point part.
+ sprintf(fmt, "%%lld.%%0%dlld%%%%", d);
+ // fmt is now "%lld.%0<d>lld%%" where <d> is 1,2,3...
+ sprintf(buf, fmt, p1, p2);
+ }
+
+ len = strlen(buf);
+ space = n_buf - len;
+ if (space < 0) space = 0; /* Allow for v. small field_width */
+ i = len;
+
+ /* Right justify in field */
+ for ( ; i >= 0; i--) buf[i + space] = buf[i];
+ for (i = 0; i < space; i++) buf[i] = ' ';
+}
+
+
+/*------------------------------------------------------------*/
+/*--- Stats ---*/
+/*------------------------------------------------------------*/
+
+/* This part excerpted from coregrind/m_translate.c */
+
+static UInt n_SP_updates_fast = 0;
+static UInt n_SP_updates_generic_known = 0;
+static UInt n_SP_updates_generic_unknown = 0;
+
+void VG_print_translation_stats ( void )
+{
+ Char buf[6];
+ UInt n_SP_updates = n_SP_updates_fast + n_SP_updates_generic_known
+ + n_SP_updates_generic_unknown;
+ VG_percentify(n_SP_updates_fast, n_SP_updates, 1, 6, buf);
+ printf(
+ "translate: fast SP updates identified: %'u (%s)\n",
+ n_SP_updates_fast, buf );
+
+ VG_percentify(n_SP_updates_generic_known, n_SP_updates, 1, 6, buf);
+ printf(
+ "translate: generic_known SP updates identified: %'u (%s)\n",
+ n_SP_updates_generic_known, buf );
+
+ VG_percentify(n_SP_updates_generic_unknown, n_SP_updates, 1, 6, buf);
+ printf(
+ "translate: generic_unknown SP updates identified: %'u (%s)\n",
+ n_SP_updates_generic_unknown, buf );
+}
+
+
+
+int main ( void )
+{
+ VG_print_translation_stats();
+ return 0;
+}
Added: branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.stderr.exp-glibc28-amd64
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.stderr.exp-glibc28-amd64 (rev 0)
+++ branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.stderr.exp-glibc28-amd64 2008-09-12 22:38:28 UTC (rev 8607)
@@ -0,0 +1,32 @@
+
+Invalid read of size 1
+ at 0x........: strlen (h_intercepts.c:109)
+ by 0x........: ...
+ by 0x........: ...
+ by 0x........: VG_print_translation_stats (bad_percentify.c:88)
+ by 0x........: main (bad_percentify.c:107)
+ Address 0x........ expected vs actual:
+ Expected: stack array "buf" in frame 3 back from here
+ Actual: unknown
+
+Invalid read of size 1
+ at 0x........: strlen (h_intercepts.c:109)
+ by 0x........: ...
+ by 0x........: ...
+ by 0x........: VG_print_translation_stats (bad_percentify.c:93)
+ by 0x........: main (bad_percentify.c:107)
+ Address 0x........ expected vs actual:
+ Expected: stack array "buf" in frame 3 back from here
+ Actual: unknown
+
+Invalid read of size 1
+ at 0x........: strlen (h_intercepts.c:109)
+ by 0x........: ...
+ by 0x........: ...
+ by 0x........: VG_print_translation_stats (bad_percentify.c:98)
+ by 0x........: main (bad_percentify.c:107)
+ Address 0x........ expected vs actual:
+ Expected: stack array "buf" in frame 3 back from here
+ Actual: unknown
+
+ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
Added: branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.stdout.exp
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.stdout.exp (rev 0)
+++ branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.stdout.exp 2008-09-12 22:38:28 UTC (rev 8607)
@@ -0,0 +1,3 @@
+translate: fast SP updates identified: 0 (--% )
+translate: generic_known SP updates identified: 0 (--% )
+translate: generic_unknown SP updates identified: 0 (--% )
Added: branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.vgtest
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.vgtest (rev 0)
+++ branches/PTRCHECK/exp-ptrcheck/tests/bad_percentify.vgtest 2008-09-12 22:38:28 UTC (rev 8607)
@@ -0,0 +1 @@
+prog: bad_percentify
|