dnscrypto-proxy: Support files updated.
[tomato.git] / release / src / router / samba3 / source / lib / clobber.c
blobd3a9c59c36bcdbd65faa13410d12c16623ea02e3
1 /*
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.
22 #include "includes.h"
24 #ifdef DEVELOPER
25 const char *global_clobber_region_function;
26 unsigned int global_clobber_region_line;
27 #endif
29 /**
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
35 * memory debugger.
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.
41 **/
42 void clobber_region(const char *fn, unsigned int line, char *dest, size_t len)
44 #ifdef DEVELOPER
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);
50 #ifdef VALGRIND
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
56 * under valgrind.) */
57 #if defined(VALGRIND_MAKE_MEM_UNDEFINED)
58 VALGRIND_MAKE_MEM_UNDEFINED(dest, len);
59 #elif defined(VALGRIND_MAKE_WRITABLE)
60 VALGRIND_MAKE_WRITABLE(dest, len);
61 #endif
62 #endif /* VALGRIND */
63 #endif /* DEVELOPER */