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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 const char *global_clobber_region_function
;
26 unsigned int global_clobber_region_line
;
30 * In developer builds, clobber a region of memory.
32 * If we think a string buffer is longer than it really is, this ought
33 * to make the failure obvious, by segfaulting (if in the heap) or by
34 * killing the return address (on the stack), or by trapping under a
37 * This is meant to catch possible string overflows, even if the
38 * actual string copied is not big enough to cause an overflow.
40 * In addition, under Valgrind the buffer is marked as uninitialized.
42 void clobber_region(const char *fn
, unsigned int line
, char *dest
, size_t len
)
45 global_clobber_region_function
= fn
;
46 global_clobber_region_line
= line
;
48 /* F1 is odd and 0xf1f1f1f1 shouldn't be a valid pointer */
49 memset(dest
, 0xF1, len
);
51 /* Even though we just wrote to this, from the application's
52 * point of view it is not initialized.
54 * (This is not redundant with the clobbering above. The
55 * marking might not actually take effect if we're not running
57 VALGRIND_MAKE_WRITABLE(dest
, len
);
59 #endif /* DEVELOPER */