00001 /* 00002 Unix SMB/CIFS implementation. 00003 Samba utility functions 00004 Copyright (C) Martin Pool 2003 00005 Copyright (C) Andrew Bartlett 2003 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 */ 00021 00022 #include "includes.h" 00023 00024 #ifdef DEVELOPER 00025 const char *global_clobber_region_function; 00026 unsigned int global_clobber_region_line; 00027 #endif 00028 00029 /** 00030 * In developer builds, clobber a region of memory. 00031 * 00032 * If we think a string buffer is longer than it really is, this ought 00033 * to make the failure obvious, by segfaulting (if in the heap) or by 00034 * killing the return address (on the stack), or by trapping under a 00035 * memory debugger. 00036 * 00037 * This is meant to catch possible string overflows, even if the 00038 * actual string copied is not big enough to cause an overflow. 00039 * 00040 * In addition, under Valgrind the buffer is marked as uninitialized. 00041 **/ 00042 void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) 00043 { 00044 #ifdef DEVELOPER 00045 global_clobber_region_function = fn; 00046 global_clobber_region_line = line; 00047 00048 /* F1 is odd and 0xf1f1f1f1 shouldn't be a valid pointer */ 00049 memset(dest, 0xF1, len); 00050 #ifdef VALGRIND 00051 /* Even though we just wrote to this, from the application's 00052 * point of view it is not initialized. 00053 * 00054 * (This is not redundant with the clobbering above. The 00055 * marking might not actually take effect if we're not running 00056 * under valgrind.) */ 00057 #if defined(VALGRIND_MAKE_MEM_UNDEFINED) 00058 VALGRIND_MAKE_MEM_UNDEFINED(dest, len); 00059 #elif defined(VALGRIND_MAKE_WRITABLE) 00060 VALGRIND_MAKE_WRITABLE(dest, len); 00061 #endif 00062 #endif /* VALGRIND */ 00063 #endif /* DEVELOPER */ 00064 }