2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Martin Pool 2003
5 Copyright (C) Andrew Bartlett 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 const char *global_clobber_region_function
;
25 unsigned int global_clobber_region_line
;
29 * In developer builds, clobber a region of memory.
31 * If we think a string buffer is longer than it really is, this ought
32 * to make the failure obvious, by segfaulting (if in the heap) or by
33 * killing the return address (on the stack), or by trapping under a
36 * This is meant to catch possible string overflows, even if the
37 * actual string copied is not big enough to cause an overflow.
39 * In addition, under Valgrind the buffer is marked as uninitialized.
41 void clobber_region(const char *fn
, unsigned int line
, char *dest
, size_t len
)
44 global_clobber_region_function
= fn
;
45 global_clobber_region_line
= line
;
47 /* F1 is odd and 0xf1f1f1f1 shouldn't be a valid pointer */
48 memset(dest
, 0xF1, len
);
50 /* Even though we just wrote to this, from the application's
51 * point of view it is not initialized.
53 * (This is not redundant with the clobbering above. The
54 * marking might not actually take effect if we're not running
56 #if defined(VALGRIND_MAKE_MEM_UNDEFINED)
57 VALGRIND_MAKE_MEM_UNDEFINED(dest
, len
);
58 #elif defined(VALGRIND_MAKE_WRITABLE)
59 VALGRIND_MAKE_WRITABLE(dest
, len
);
62 #endif /* DEVELOPER */