From cbbad87e5b849a7132a2ebf58ab1f31cbeecd224 Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Fri, 15 Mar 2013 10:55:36 -0600 Subject: [PATCH 1/5] - Build tests with -fno-builtin --- memstomp-testsuite.patch | 4 ++-- memstomp.spec | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/memstomp-testsuite.patch b/memstomp-testsuite.patch index fbd9c12..7e63d12 100644 --- a/memstomp-testsuite.patch +++ b/memstomp-testsuite.patch @@ -669,7 +669,7 @@ diff -Nrup a/testsuite/memstomp.overlap/wmempcpy.c b/testsuite/memstomp.overlap/ + + set src [lindex $sources 0] + -+ if {[catch {exec gcc $src} results]} { ++ if {[catch {exec gcc -fno-builtin $src} results]} { + fail "$src compilation $results" + } else { + pass "$src compilation $results" @@ -728,7 +728,7 @@ diff -Nrup a/testsuite/memstomp.overlap/wmempcpy.c b/testsuite/memstomp.overlap/ + global memstomp + set src [lindex $sources 0] + -+ if {[catch {exec gcc $src} results]} { ++ if {[catch {exec gcc -fno-builtin $src} results]} { + fail "$src compilation $results" + } else { + pass "$src compilation $results" diff --git a/memstomp.spec b/memstomp.spec index d1b8bbe..8891884 100644 --- a/memstomp.spec +++ b/memstomp.spec @@ -1,7 +1,7 @@ %global githash 38573e7d Name: memstomp Version: 0.1.4 -Release: 4%{?dist} +Release: 5%{?dist} Summary: Warns of memory argument overlaps to various functions Group: Development/Debuggers # The entire source code is LGPLV3+ with the exception of backtrace-symbols.c which @@ -53,6 +53,9 @@ make install DESTDIR=$RPM_BUILD_ROOT %{_mandir}/man1/memstomp.1.gz %changelog +* Fri Mar 15 2013 Jeff Law 0.1.4-4 +- Build tests with -fno-builtin + * Mon Mar 11 2013 Jeff Law 0.1.4-4 - Add manpage - Add initial testsuite From 4efbb3b54423aa65e8a2fb2679d91fb7ec1ead4f Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Thu, 9 May 2013 22:26:19 -0600 Subject: [PATCH 2/5] Fix typo in initialization message (#961495) --- memstomp-rh961495.patch | 12 ++++++++++++ memstomp.spec | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 memstomp-rh961495.patch diff --git a/memstomp-rh961495.patch b/memstomp-rh961495.patch new file mode 100644 index 0000000..49b7345 --- /dev/null +++ b/memstomp-rh961495.patch @@ -0,0 +1,12 @@ +diff -Nrup a/memstomp.c b/memstomp.c +--- a/memstomp.c 2011-03-30 21:27:19.000000000 -0600 ++++ b/memstomp.c 2013-05-09 22:23:39.210837345 -0600 +@@ -174,7 +174,7 @@ static void setup(void) { + initialized = true; + + char prname[17]; +- fprintf(stderr, "memstomp: "PACKAGE_VERSION" sucessfully initialized for process %s (pid %lu).\n", ++ fprintf(stderr, "memstomp: "PACKAGE_VERSION" successfully initialized for process %s (pid %lu).\n", + get_prname(prname), (unsigned long) getpid()); + } + diff --git a/memstomp.spec b/memstomp.spec index 8891884..97e0b9c 100644 --- a/memstomp.spec +++ b/memstomp.spec @@ -1,7 +1,7 @@ %global githash 38573e7d Name: memstomp Version: 0.1.4 -Release: 5%{?dist} +Release: 6%{?dist} Summary: Warns of memory argument overlaps to various functions Group: Development/Debuggers # The entire source code is LGPLV3+ with the exception of backtrace-symbols.c which @@ -20,6 +20,7 @@ BuildRequires: binutils-devel autoconf automake dejagnu Patch0: memstomp-testsuite.patch Patch1: memstomp-man.patch +Patch2: memstomp-rh961495.patch %description @@ -34,6 +35,7 @@ overlapping memory arguments to certain library calls. %setup -q -n %{name}-%{version}-%{githash} %patch0 -p1 %patch1 -p1 +%patch2 -p1 %build @@ -53,6 +55,9 @@ make install DESTDIR=$RPM_BUILD_ROOT %{_mandir}/man1/memstomp.1.gz %changelog +* Thu May 09 2013 Jeff Law 0.1.4-5 +- Fix typo in initialization message (#961495) + * Fri Mar 15 2013 Jeff Law 0.1.4-4 - Build tests with -fno-builtin From adcfaf979267ba032c07319efa142e21959c83d0 Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Fri, 10 May 2013 17:55:35 -0600 Subject: [PATCH 3/5] Improve man page (#961518) --- memstomp-man.patch | 81 +++++++++++++++++++++++++++++++++++++--------- memstomp.spec | 5 ++- 2 files changed, 70 insertions(+), 16 deletions(-) diff --git a/memstomp-man.patch b/memstomp-man.patch index d06462f..b6839f6 100644 --- a/memstomp-man.patch +++ b/memstomp-man.patch @@ -9,25 +9,76 @@ CLEANFILES = \ memstomp ---- /dev/null 2013-02-26 15:11:24.372721019 -0700 -+++ b/memstomp.man 2013-03-11 21:54:06.847082615 -0600 -@@ -0,0 +1,19 @@ +diff -Nrup a/memstomp.man b/memstomp.man +--- a/memstomp.man 1969-12-31 17:00:00.000000000 -0700 ++++ b/memstomp.man 2013-05-10 17:53:37.767722170 -0600 +@@ -0,0 +1,69 @@ +.\" This is a comment +.\" Contact Owen@thelinuxblog.com -+.TH memstomp 1 "05 February 2013" ".1" "memstomp" ++.TH MEMSTOMP 1 "09 April 2013" "0.1.4" +.SH NAME -+memstomp ++memstomp \- detect function calls with overlapping memory regions +.SH SYNOPSIS -+memstomp [OPTIONS...] APPLICATION [ARGUMENTS...] ++.B memstomp ++.RB [ \-dk ] ++.I application ++.RI [ argument ...] ++.PP ++.B memstomp ++.B \-h +.SH DESCRIPTION -+memstomp can help detect memory argument overlaps to various mem* and str* functions. ++The ++.B memstomp ++utility identifies function calls that use overlapping memory regions in situations when such an overlap is not allowed by various standards. When a problem is detected, memstomp displays a backtrace to help you debug the problem, and if executed with the ++.B \-\-debug\-info ++command line option, it even uses the available debugging information. Since the backtrace code is not thread safe, memstomp also allows you to use the ++.B \-\-kill ++option to immediately terminate the analyzed program when an invalid function call is detected. ++.PP ++This version of memstomp inspects the following function calls: ++.BR memcpy (), ++.BR memccpy (), ++.BR mempcpy (), ++.BR strcpy (), ++.BR stpcpy (), ++.BR strncpy (), ++.BR stpncpy (), ++.BR strcat (), ++.BR strncat (), ++.BR wmemcpy (), ++.BR wmempcpy (), ++.BR wcscpy (), ++.BR wcsncpy (), ++.BR wcscat (), ++and ++.BR wcsncat (). +.SH OPTIONS -+-h, --help Show help -+ -+-d, --debug-info Make use of debug information in stack traces -+ -+-k, --kill Kill application when problem is detected -+ ++.TP ++.BR \-d ", " \-\-debug\-info ++Make use of debugging information to produce more detailed stack traces. ++.TP ++.BR \-k ", " \-\-kill ++Kill the analyzed application when a problem is detected. ++.TP ++.BR \-h ", " \-\-help ++Display usage information and exit. +.SH SEE ALSO -+.SH BUGS -+ ++.BR memcpy (3), ++.BR memccpy (3), ++.BR mempcpy (3), ++.BR strcpy (3), ++.BR stpcpy (3), ++.BR strncpy (3), ++.BR stpncpy (3), ++.BR strcat (3), ++.BR strncat (3), ++.BR wmemcpy (3), ++.BR wmempcpy (3), ++.BR wcscpy (3), ++.BR wcsncpy (3), ++.BR wcscat (3), ++.BR wcsncat (3) ++.SH AUTHORS ++Lennart Poettering ++.br ++William Cohen diff --git a/memstomp.spec b/memstomp.spec index 97e0b9c..3f00fcc 100644 --- a/memstomp.spec +++ b/memstomp.spec @@ -1,7 +1,7 @@ %global githash 38573e7d Name: memstomp Version: 0.1.4 -Release: 6%{?dist} +Release: 7%{?dist} Summary: Warns of memory argument overlaps to various functions Group: Development/Debuggers # The entire source code is LGPLV3+ with the exception of backtrace-symbols.c which @@ -55,6 +55,9 @@ make install DESTDIR=$RPM_BUILD_ROOT %{_mandir}/man1/memstomp.1.gz %changelog +* Fri May 10 2013 Jeff Law 0.1.4-7 +- Improve man page (#961518) + * Thu May 09 2013 Jeff Law 0.1.4-5 - Fix typo in initialization message (#961495) From 5880f6b115d6dcc5e5af8d985b93c9cfcbbcc93a Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Tue, 14 May 2013 15:36:43 -0600 Subject: [PATCH 4/5] Link in libiberty (#962763) --- memstomp-rh962763.patch | 15 +++++++++++++++ memstomp.spec | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 memstomp-rh962763.patch diff --git a/memstomp-rh962763.patch b/memstomp-rh962763.patch new file mode 100644 index 0000000..9fce643 --- /dev/null +++ b/memstomp-rh962763.patch @@ -0,0 +1,15 @@ +diff -Nrup a/configure.ac b/configure.ac +--- a/configure.ac 2013-05-14 14:27:04.316530952 -0600 ++++ b/configure.ac 2013-05-14 14:27:37.854394379 -0600 +@@ -72,8 +72,10 @@ AC_CHECK_HEADERS([sys/poll.h]) + AC_CHECK_HEADERS([sys/ioctl.h]) + AC_CHECK_HEADERS([byteswap.h]) + ++AC_SEARCH_LIBS([htab_find_slot], [iberty], [], [AC_MSG_ERROR([*** libiberty not found])]) ++AC_CHECK_HEADERS([libiberty.h], [], [AC_MSG_ERROR([*** libiberty.h header not found])]) + AC_SEARCH_LIBS([bfd_init], [bfd], [], [AC_MSG_ERROR([*** libbfd not found])]) +-AC_CHECK_HEADERS([bfd.h], [], [AC_MSG_ERROR([*** POSIX caps headers not found])]) ++AC_CHECK_HEADERS([bfd.h], [], [AC_MSG_ERROR([*** bfd.h header not found])]) + + #### Typdefs, structures, etc. #### + diff --git a/memstomp.spec b/memstomp.spec index 3f00fcc..e9b7c5b 100644 --- a/memstomp.spec +++ b/memstomp.spec @@ -1,7 +1,7 @@ %global githash 38573e7d Name: memstomp Version: 0.1.4 -Release: 7%{?dist} +Release: 8%{?dist} Summary: Warns of memory argument overlaps to various functions Group: Development/Debuggers # The entire source code is LGPLV3+ with the exception of backtrace-symbols.c which @@ -21,6 +21,7 @@ BuildRequires: binutils-devel autoconf automake dejagnu Patch0: memstomp-testsuite.patch Patch1: memstomp-man.patch Patch2: memstomp-rh961495.patch +Patch3: memstomp-rh962763.patch %description @@ -36,6 +37,7 @@ overlapping memory arguments to certain library calls. %patch0 -p1 %patch1 -p1 %patch2 -p1 +%patch3 -p1 %build @@ -55,6 +57,9 @@ make install DESTDIR=$RPM_BUILD_ROOT %{_mandir}/man1/memstomp.1.gz %changelog +* Tue May 14 2013 Jeff Law 0.1.4-8 +- Link in libiberty too (#962763) + * Fri May 10 2013 Jeff Law 0.1.4-7 - Improve man page (#961518) From 7b972e2360bb068c16fde4eec709159410669b71 Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Thu, 30 May 2013 06:09:42 -0600 Subject: [PATCH 5/5] - Add -q/--quiet options for quiet mode. --- memstomp-quietmode.patch | 83 ++++++++++++++++++++++++++++++++++++++++ memstomp.spec | 7 +++- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 memstomp-quietmode.patch diff --git a/memstomp-quietmode.patch b/memstomp-quietmode.patch new file mode 100644 index 0000000..727ffed --- /dev/null +++ b/memstomp-quietmode.patch @@ -0,0 +1,83 @@ +diff -Nrup a/memstomp.c b/memstomp.c +--- a/memstomp.c 2013-05-30 06:02:56.578486389 -0600 ++++ b/memstomp.c 2013-05-30 06:06:42.648731070 -0600 +@@ -64,6 +64,8 @@ + + static bool abrt_trap = false; + ++static bool quiet_mode = false; ++ + #ifndef SCHED_RESET_ON_FORK + /* "Your libc lacks the definition of SCHED_RESET_ON_FORK. We'll now + * define it ourselves, however make sure your kernel is new +@@ -162,7 +164,10 @@ static void setup(void) { + if (LIKELY(initialized)) + return; + +- if (!dlsym(NULL, "main")) ++ if (getenv("MEMSTOMP_QUIET")) ++ quiet_mode = true; ++ ++ if (!dlsym(NULL, "main") && !quiet_mode) + fprintf(stderr, + "memstomp: Application appears to be compiled without -rdynamic. It might be a\n" + "memstomp: good idea to recompile with -rdynamic enabled since this produces more\n" +@@ -173,9 +178,11 @@ static void setup(void) { + + initialized = true; + +- char prname[17]; +- fprintf(stderr, "memstomp: "PACKAGE_VERSION" successfully initialized for process %s (pid %lu).\n", +- get_prname(prname), (unsigned long) getpid()); ++ if (!quiet_mode) { ++ char prname[17]; ++ fprintf(stderr, "memstomp: "PACKAGE_VERSION" successfully initialized for process %s (pid %lu).\n", ++ get_prname(prname), (unsigned long) getpid()); ++ } + } + + static void show_summary(void) { } +diff -Nrup a/memstomp.in b/memstomp.in +--- a/memstomp.in 2011-03-30 21:27:19.000000000 -0600 ++++ b/memstomp.in 2013-05-30 06:06:42.649731067 -0600 +@@ -18,7 +18,7 @@ + # You should have received a copy of the GNU Lesser General Public + # License along with memstomp. If not, see . + +-if ! TEMP=`getopt -o +dhk --long help,debug-info,kill -n memstomp -- "$@"` ; then ++if ! TEMP=`getopt -o +dqhk --long help,quiet,debug-info,kill -n memstomp -- "$@"` ; then + exit 1 + fi + +@@ -38,6 +38,10 @@ while : ; do + shift 1 + ;; + ++ -q|--quiet) ++ export MEMSTOMP_QUIET=1 ++ shift 1 ++ ;; + + -h|--help) + cat < 0.1.4-9 +- Add -q/--quiet options for quiet mode. + * Tue May 14 2013 Jeff Law 0.1.4-8 - Link in libiberty too (#962763)