From a084f06fe33eb9903489763bc34c7092080a0a5e Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 18 Mar 2003 07:09:23 +0000 Subject: Split "clobber" function and variables into its own file before it grows too much larger. (This used to be commit 4bbddbfc6a97ebb11e299aa7bd07ebebeab42c65) --- source3/lib/clobber.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 source3/lib/clobber.c (limited to 'source3/lib/clobber.c') diff --git a/source3/lib/clobber.c b/source3/lib/clobber.c new file mode 100644 index 0000000000..fb3a0dc281 --- /dev/null +++ b/source3/lib/clobber.c @@ -0,0 +1,60 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Martin Pool 2003 + Copyright (C) Andrew Bartlett 2003 + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#ifdef DEVELOPER +const char *global_clobber_region_function; +unsigned int global_clobber_region_line; +#endif + +/** + * In developer builds, clobber a region of memory. + * + * If we think a string buffer is longer than it really is, this ought + * to make the failure obvious, by segfaulting (if in the heap) or by + * killing the return address (on the stack), or by trapping under a + * memory debugger. + * + * This is meant to catch possible string overflows, even if the + * actual string copied is not big enough to cause an overflow. + * + * In addition, under Valgrind the buffer is marked as uninitialized. + **/ +void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) +{ +#ifdef DEVELOPER + global_clobber_region_function = fn; + global_clobber_region_line = line; + + /* F1 is odd and 0xf1f1f1f1 shouldn't be a valid pointer */ + memset(dest, 0xF1, len); +#ifdef VALGRIND + /* Even though we just wrote to this, from the application's + * point of view it is not initialized. + * + * (This is not redundant with the clobbering above. The + * marking might not actually take effect if we're not running + * under valgrind.) */ + VALGRIND_MAKE_WRITABLE(dest, len); +#endif /* VALGRIND */ +#endif /* DEVELOPER */ +} -- cgit From 8d7c88667190fe286971ac4fffb64ee5bd9eeeb0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Oct 2005 03:24:00 +0000 Subject: r11137: Compile with only 2 warnings (I'm still working on that code) on a gcc4 x86_64 box. Jeremy. (This used to be commit d720867a788c735e56d53d63265255830ec21208) --- source3/lib/clobber.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/clobber.c') diff --git a/source3/lib/clobber.c b/source3/lib/clobber.c index fb3a0dc281..f39b94538e 100644 --- a/source3/lib/clobber.c +++ b/source3/lib/clobber.c @@ -54,7 +54,9 @@ void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) * (This is not redundant with the clobbering above. The * marking might not actually take effect if we're not running * under valgrind.) */ +#if 0 VALGRIND_MAKE_WRITABLE(dest, len); +#endif #endif /* VALGRIND */ #endif /* DEVELOPER */ } -- cgit From 3bbad5ec3da3bbfef33d2c529531777413a8a221 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Oct 2005 18:08:23 +0000 Subject: r11156: Remove valgrind disabling ifdef that got added by mistake. Jeremy. (This used to be commit fc9eca51e02022ccffbad2a4f2450f85e558e151) --- source3/lib/clobber.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/lib/clobber.c') diff --git a/source3/lib/clobber.c b/source3/lib/clobber.c index f39b94538e..fb3a0dc281 100644 --- a/source3/lib/clobber.c +++ b/source3/lib/clobber.c @@ -54,9 +54,7 @@ void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) * (This is not redundant with the clobbering above. The * marking might not actually take effect if we're not running * under valgrind.) */ -#if 0 VALGRIND_MAKE_WRITABLE(dest, len); -#endif #endif /* VALGRIND */ #endif /* DEVELOPER */ } -- cgit From d1f91f7c723733113b4e9792042101c80dfc064c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Dec 2005 06:46:46 +0000 Subject: r12043: It's amazing the warnings you find when compiling on a 64-bit box with gcc4 and -O6... Fix a bunch of C99 dereferencing type-punned pointer will break strict-aliasing rules errors. Also added prs_int32 (not uint32...) as it's needed in one place. Find places where prs_uint32 was being used to marshall/unmarshall a time_t (a big no no on 64-bits). More warning fixes to come. Thanks to Volker for nudging me to compile like this. Jeremy. (This used to be commit c65b752604f8f58abc4e7ae8514dc2c7f086271c) --- source3/lib/clobber.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/clobber.c') diff --git a/source3/lib/clobber.c b/source3/lib/clobber.c index fb3a0dc281..54b24ffed3 100644 --- a/source3/lib/clobber.c +++ b/source3/lib/clobber.c @@ -54,7 +54,7 @@ void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) * (This is not redundant with the clobbering above. The * marking might not actually take effect if we're not running * under valgrind.) */ - VALGRIND_MAKE_WRITABLE(dest, len); +// VALGRIND_MAKE_WRITABLE(dest, len); #endif /* VALGRIND */ #endif /* DEVELOPER */ } -- cgit From e03a68ff7ec92700d4c53fa6b2e029befce9370c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Jan 2006 20:23:02 +0000 Subject: r12855: Remove erroneous commenting out of valgrind fix. Jeremy. (This used to be commit b76c7b613282dc89c54faf3e7cef98f7651c5a9d) --- source3/lib/clobber.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/clobber.c') diff --git a/source3/lib/clobber.c b/source3/lib/clobber.c index 54b24ffed3..fb3a0dc281 100644 --- a/source3/lib/clobber.c +++ b/source3/lib/clobber.c @@ -54,7 +54,7 @@ void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) * (This is not redundant with the clobbering above. The * marking might not actually take effect if we're not running * under valgrind.) */ -// VALGRIND_MAKE_WRITABLE(dest, len); + VALGRIND_MAKE_WRITABLE(dest, len); #endif /* VALGRIND */ #endif /* DEVELOPER */ } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/clobber.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/clobber.c') diff --git a/source3/lib/clobber.c b/source3/lib/clobber.c index fb3a0dc281..b18fc7b1a9 100644 --- a/source3/lib/clobber.c +++ b/source3/lib/clobber.c @@ -6,7 +6,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/clobber.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/clobber.c') diff --git a/source3/lib/clobber.c b/source3/lib/clobber.c index b18fc7b1a9..b97262a055 100644 --- a/source3/lib/clobber.c +++ b/source3/lib/clobber.c @@ -15,8 +15,7 @@ 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., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 0b33d60affc321d549178b78a39e9df910dfe74f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 15 Dec 2007 23:05:30 -0800 Subject: Cope with valgrind > 3.2.x. Jeremy. (This used to be commit e799eb8da6f5e7a2173ba6b8fb040430fd1c6f34) --- source3/lib/clobber.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/clobber.c') diff --git a/source3/lib/clobber.c b/source3/lib/clobber.c index b97262a055..e77e786fb5 100644 --- a/source3/lib/clobber.c +++ b/source3/lib/clobber.c @@ -53,7 +53,11 @@ void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) * (This is not redundant with the clobbering above. The * marking might not actually take effect if we're not running * under valgrind.) */ +#if defined(VALGRIND_MAKE_MEM_UNDEFINED) + VALGRIND_MAKE_MEM_UNDEFINED(dest, len); +#elif defined(VALGRIND_MAKE_WRITABLE) VALGRIND_MAKE_WRITABLE(dest, len); +#endif #endif /* VALGRIND */ #endif /* DEVELOPER */ } -- cgit