]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Compat: Shuffle squid.h portability definitions into libcompat
authorAmos Jeffries <amosjeffries@squid-cache.org>
Sun, 21 Mar 2010 03:08:26 +0000 (21:08 -0600)
committerAmos Jeffries <amosjeffries@squid-cache.org>
Sun, 21 Mar 2010 03:08:26 +0000 (21:08 -0600)
* Improves and shuffles the memory allocator and string buffer protection
* Fixing many of the unsafe string buffer handling helpers
* removing several duplicated hacks already in libcompat
* Adds NetBSD portability file

48 files changed:
compat/GnuRegex.c
compat/Makefile.am
compat/compat.h
compat/compat_shared.h
compat/os/dragonfly.h
compat/os/freebsd.h
compat/os/hpux.h
compat/os/mswin.h
compat/os/netbsd.h [new file with mode: 0644]
compat/os/openbsd.h
compat/os/sunos.h
compat/unsafe.h [new file with mode: 0644]
helpers/basic_auth/MSNT/smblib.c
helpers/basic_auth/MSNT/std-includes.h
helpers/basic_auth/NCSA/crypt_md5.cc
helpers/basic_auth/PAM/basic_pam_auth.cc
helpers/digest_auth/password/text_backend.c
helpers/negotiate_auth/kerberos/negotiate_kerberos_auth.cc
helpers/negotiate_auth/kerberos/negotiate_kerberos_auth_test.cc
helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c
helpers/ntlm_auth/smb_lm/smbval/byteorder.h
helpers/ntlm_auth/smb_lm/smbval/rfcnb-util.c
helpers/ntlm_auth/smb_lm/smbval/session.c
helpers/ntlm_auth/smb_lm/smbval/smblib-util.c
helpers/ntlm_auth/smb_lm/smbval/smblib.c
include/MemPool.h
lib/MemPool.cc
lib/Profiler.c
lib/util.c
snmplib/mib.c
src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc
src/DiskIO/DiskThreads/aiops.cc
src/DiskIO/DiskThreads/async_io.cc
src/acl/Strategised.h
src/auth/digest/auth_digest.cc
src/cbdata.cc
src/comm_poll.cc
src/dlink.cc
src/helper.cc
src/htcp.cc
src/mem.cc
src/pconn.cc
src/repl/lru/store_repl_lru.cc
src/squid.h
src/store.cc
test-suite/MemPoolTest.cc
test-suite/test_tools.cc
tools/squidclient.cc

index b5ba9eb6b544c4c0c490b4ed4b14fc9423d9c98f..250d336498989027a1d38ab78b601285c24c8cd4 100644 (file)
@@ -32,6 +32,7 @@
 #define _GNU_SOURCE 1
 #endif
 
+#define SQUID_NO_ALLOC_PROTECT 1
 #include "config.h"
 
 #if USE_GNUREGEX /* only if squid needs it. Usually not */
index 77c1fc31dcfdcf302d23d67550c9ac3b1177e6ee..4c9f8e2404a21dd7629a85281f953c438db157c0 100644 (file)
@@ -20,6 +20,7 @@ libcompat_la_SOURCES = \
        osdetect.h \
        stdvarargs.h \
        types.h \
+       unsafe.h \
        valgrind.h \
        \
        os/aix.h \
@@ -28,6 +29,7 @@ libcompat_la_SOURCES = \
        os/hpux.h \
        os/linux.h \
        os/mswin.h \
+       os/netbsd.h \
        os/next.h \
        os/openbsd.h \
        os/os2.h \
index a4d20698df8517103e6611d9cdb6bda455807102..72607760671e9ff9bd72f82f35b3577bb5f09007 100644 (file)
@@ -55,6 +55,7 @@
 #include "compat/os/hpux.h"
 #include "compat/os/linux.h"
 #include "compat/os/mswin.h"
+#include "compat/os/netbsd.h"
 #include "compat/os/next.h"
 #include "compat/os/openbsd.h"
 #include "compat/os/os2.h"
@@ -95,5 +96,7 @@
  */
 #include "compat/GnuRegex.h"
 
+/* some functions are unsafe to be used in Squid. */
+#include "compat/unsafe.h"
 
 #endif /* _SQUID_COMPAT_H */
index 4abc979b97be4d8c5f24994ea733b18bc9d754d3..95c54e72244bf86cf68498ee812562b460301440 100644 (file)
@@ -36,7 +36,6 @@
 #if HAVE_DIRENT_H
 #include <dirent.h>
 #define NAMLEN(dirent) strlen((dirent)->d_name)
-
 #else /* if not HAVE_DIRENT_H */
 #define dirent direct
 #define NAMLEN(dirent) (dirent)->d_namlen
@@ -173,6 +172,7 @@ max(A const & lhs, A const & rhs)
 #endif
 
 
+#ifndef SQUID_NONBLOCK
 /* REQUIRED for the below logics. If they move this needs to as well */
 #if HAVE_FCNTL_H
 #include <fcntl.h>
@@ -189,7 +189,7 @@ max(A const & lhs, A const & rhs)
 /** O_NDELAY is our fallback. */
 #define SQUID_NONBLOCK O_NDELAY
 #endif
-
+#endif
 
 /**
  * Signalling flags are apparently not always provided.
@@ -211,8 +211,8 @@ max(A const & lhs, A const & rhs)
 
 
 /**
- * com_err.h is a C header and needs excplicit shielding, but not
- * all other system headers including this care to do this.
+ * com_err.h is a C header and needs explicit shielding, but not
+ * all other system headers including this care to do so.
  */
 #ifdef __cplusplus
 #if HAVE_ET_COM_ERR_H
index e7fa90448f6005006fd08f17f34d2226bcadf284..5c767fc55429add45dabcd59afe3c6e3a4229cc1 100644 (file)
 #undef HAVE_MALLOC_H
 #endif
 
+/* Exclude CPPUnit tests from the allocator restrictions. */
+/* BSD implementation uses these still */
+#if defined(SQUID_UNIT_TEST)
+#define SQUID_NO_ALLOC_PROTECT 1
+#endif
 
 #endif /* _SQUID_DRAGONFLY_ */
 #endif /* SQUID_OS_DRAGONFLY_H */
index e4fb395942f488ca602db115c71fc475259c1320..05061fae6128af2420053c95f71c929662ee6466 100644 (file)
 
 #define _etext etext
 
+/* Exclude CPPUnit tests from the allocator restrictions. */
+/* BSD implementation uses these still */
+#if defined(SQUID_UNIT_TEST)
+#define SQUID_NO_ALLOC_PROTECT 1
+#endif
+
+
 #endif /* _SQUID_FREEBSD_ */
 #endif /* SQUID_OS_FREEBSD_H */
index 993d14d4c44a97304f174b493dcf3d1e97a6cd2c..25fdae1e6431092af6db277329410ffb93170e84 100644 (file)
 #define getrusage(a, b)  syscall(SYS_GETRUSAGE, a, b)
 #endif
 
+/*
+ * getpagesize(...) not available on HPUX
+ */
+#if !defined(HAVE_GETPAGESIZE)
+#define HAVE_GETPAGESIZE
+#define getpagesize( )   sysconf(_SC_PAGE_SIZE)
+#endif
 
 #endif /* _SQUID_HPUX_ */
 #endif /* SQUID_OS_HPUX_H */
index 669ee7e0d1e08cb099b885e11076aa497c28b67e..aa90975208a8da3c3028e84fabfe73f1c0ae0033 100644 (file)
@@ -716,5 +716,10 @@ struct rusage {
 
 #undef ACL
 
+#if !defined(getpagesize)
+/* Windows may lack getpagesize() prototype */
+SQUIDCEXTERN size_t getpagesize(void);
+#endif
+
 #endif /* _SQUID_WIN32_ */
 #endif /* SQUID_OS_MSWIN_H */
diff --git a/compat/os/netbsd.h b/compat/os/netbsd.h
new file mode 100644 (file)
index 0000000..300f2d3
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef SQUID_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef SQUID_OS_NETBSD_H
+#define SQUID_OS_NETBSD_H
+
+#ifdef _SQUID_NETBSD_
+
+/****************************************************************************
+ *--------------------------------------------------------------------------*
+ * DO *NOT* MAKE ANY CHANGES below here unless you know what you're doing...*
+ *--------------------------------------------------------------------------*
+ ****************************************************************************/
+
+/* Exclude CPPUnit tests from the allocator restrictions. */
+/* BSD implementation uses these still */
+#if defined(SQUID_UNIT_TEST)
+#define SQUID_NO_ALLOC_PROTECT 1
+#endif
+
+#endif /* _SQUID_NETBSD_ */
+#endif /* SQUID_OS_NETBSD_H */
index eae2cdf003bd0042edddce73f60e801d49fe0ded..4f4597a14708899b6abf06971d12f89387b29c46 100644 (file)
 #undef HAVE_MALLOC_H
 #endif
 
+/* Exclude CPPUnit tests from the allocator restrictions. */
+/* BSD implementation uses these still */
+#if defined(SQUID_UNIT_TEST)
+#define SQUID_NO_ALLOC_PROTECT 1
+#endif
 
 #endif /* _SQUID_OPENBSD_ */
 #endif /* SQUID_OS_OPENBSD_H */
index 25f891e5daa8d7ec74906f25fb8e8d0ac92c2b64..f1c67894b9654861f99eea07a66a21acae19f402 100644 (file)
  ****************************************************************************/
 
 
+/* O_NONBLOCK requires <fcntl.h> to be included first */
+#if HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
 /*
  * We assume O_NONBLOCK is broken, or does not exist, on SunOS.
  */
diff --git a/compat/unsafe.h b/compat/unsafe.h
new file mode 100644 (file)
index 0000000..88af1fe
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef SQUID_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef _SQUID_COMPAT_UNSAFE_H
+#define _SQUID_COMPAT_UNSAFE_H
+
+/*
+ * Trap unintentional use of functions unsafe for use within squid.
+ */
+
+#if !SQUID_NO_ALLOC_PROTECT
+#ifndef free
+#define free(x) ERROR_free_UNSAFE_IN_SQUID(x)
+#endif
+#ifndef malloc
+#define malloc ERROR_malloc_UNSAFE_IN_SQUID
+#endif
+#ifndef calloc
+#define calloc ERROR_calloc_UNSAFE_IN_SQUID
+#endif
+#endif /* !SQUID_NO_ALLOC_PROTECT */
+
+#if !SQUID_NO_STRING_BUFFER_PROTECT
+#ifndef sprintf
+#define sprintf ERROR_sprintf_UNSAFE_IN_SQUID
+#endif
+#ifndef strdup
+#define strdup ERROR_strdup_UNSAFE_IN_SQUID
+#endif
+#endif /* SQUID_NO_STRING_BUFFER_PROTECT */
+
+#endif /* _SQUID_COMPAT_UNSAFE_H */
index b59cc722c3e41354570ab247636ac19316a22714..518a924a65ad97e6c4bfff8c571fa6e15c96103d 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
+#define SQUID_NO_ALLOC_PROTECT 1
 
-int SMBlib_errno;
-int SMBlib_SMB_Error;
-#define SMBLIB_ERRNO
-#define uchar unsigned char
 #include "util.h"
 #include "smblib-priv.h"
 #include "smblib.h"
@@ -41,6 +38,11 @@ int SMBlib_SMB_Error;
 #include <string.h>
 #include <signal.h>
 
+#define SMBLIB_ERRNO
+#define uchar unsigned char
+
+int SMBlib_errno;
+int SMBlib_SMB_Error;
 SMB_State_Types SMBlib_State;
 
 /* Initialize the SMBlib package     */
index 9419829392ee55159c932edef078cadef1d2b52f..619b45854be5e559eccc6ea3ccb279c249f171b6 100644 (file)
  */
 
 /* the types are provided by squid's configure preocess */
+#define SQUID_NO_ALLOC_PROTECT 1
 #include "config.h"
+
 #define BOOL int16_t
 #define int16 int16_t
 
 #include <netdb.h>
-#include <sys/types.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
 #include <signal.h>
index 5823db96e0fb7818f25f3a16236f9908631867f3..410ac4fa04a6d59b4203cc97e6ca2a323018fd17 100644 (file)
@@ -189,7 +189,7 @@ char *md5sum(const char *s)
     SquidMD5Final(digest,&ctx);
 
     for (idx=0; idx<16; idx++)
-        sprintf(&sum[idx*2],"%02x",digest[idx]);
+        snprintf(&sum[idx*2],(33-(idx*2)),"%02x",digest[idx]);
 
     sum[32]='\0';
 
index dd873856cd125d36b8d006225595c3276c61b5ee..6a2a31abf62ad74ad4c8f6dce55e772d78c68c5f 100644 (file)
@@ -65,6 +65,8 @@
  *
  * Compile this program with: gcc -o basic_pam_auth basic_pam_auth.cc -lpam -ldl
  */
+#define SQUID_NO_ALLOC_PROTECT 1
+#define SQUID_NO_STRING_BUFFER_PROTECT 1
 #include "config.h"
 
 #include "rfc1738.h"
index 9bbaf1d479536d010231eeeb00306b76ff16a724..a934bbb11cb5bd9b9e09b4d58f8ef4e040e5ef12 100644 (file)
@@ -28,6 +28,8 @@
  *
  * Copyright (c) 2003  Robert Collins  <robertc@squid-cache.org>
  */
+#define SQUID_NO_ALLOC_PROTECT 1
+#include "config.h"
 
 #include "text_backend.h"
 
index 68f2a789749b5bb9def9eef7f67322e4bdcb8ad9..1f575736a27ab6ba155d00390092c1160c5ae163 100644 (file)
@@ -171,7 +171,7 @@ check_gss_err(OM_uint32 major_status, OM_uint32 minor_status,
                                           GSS_C_GSS_CODE, GSS_C_NULL_OID, &msg_ctx, &status_string);
             if (maj_stat == GSS_S_COMPLETE) {
                 if (sizeof(buf) > len + status_string.length + 1) {
-                    sprintf(buf + len, "%s", (char *) status_string.value);
+                    snprintf(buf + len, (sizeof(buf)-len), "%s", (char *) status_string.value);
                     len += status_string.length;
                 }
                 gss_release_buffer(&min_stat, &status_string);
@@ -180,7 +180,7 @@ check_gss_err(OM_uint32 major_status, OM_uint32 minor_status,
             gss_release_buffer(&min_stat, &status_string);
         }
         if (sizeof(buf) > len + 2) {
-            sprintf(buf + len, "%s", ". ");
+            snprintf(buf + len, (sizeof(buf)-len), "%s", ". ");
             len += 2;
         }
         msg_ctx = 0;
@@ -190,7 +190,7 @@ check_gss_err(OM_uint32 major_status, OM_uint32 minor_status,
                                           GSS_C_MECH_CODE, GSS_C_NULL_OID, &msg_ctx, &status_string);
             if (maj_stat == GSS_S_COMPLETE) {
                 if (sizeof(buf) > len + status_string.length) {
-                    sprintf(buf + len, "%s", (char *) status_string.value);
+                    snprintf(buf + len,(sizeof(buf)-len), "%s", (char *) status_string.value);
                     len += status_string.length;
                 }
                 gss_release_buffer(&min_stat, &status_string);
index 90ea8067b651fc51d62f3076a2c8bc75af3792f0..f15ebb515ce0d72f11f3408e6f35c3049537784a 100644 (file)
@@ -122,7 +122,7 @@ check_gss_err(OM_uint32 major_status, OM_uint32 minor_status,
                                           GSS_C_GSS_CODE, GSS_C_NULL_OID, &msg_ctx, &status_string);
             if (maj_stat == GSS_S_COMPLETE) {
                 if (sizeof(buf) > len + status_string.length + 1) {
-                    sprintf(buf + len, "%s", (char *) status_string.value);
+                    snprintf(buf + len, (sizeof(buf)-len), "%s", (char *)status_string.value);
                     len += status_string.length;
                 }
                 gss_release_buffer(&min_stat, &status_string);
@@ -131,7 +131,7 @@ check_gss_err(OM_uint32 major_status, OM_uint32 minor_status,
             gss_release_buffer(&min_stat, &status_string);
         }
         if (sizeof(buf) > len + 2) {
-            sprintf(buf + len, "%s", ". ");
+            snprintf(buf + len, (sizeof(buf)-len), "%s", ". ");
             len += 2;
         }
         msg_ctx = 0;
@@ -141,7 +141,7 @@ check_gss_err(OM_uint32 major_status, OM_uint32 minor_status,
                                           GSS_C_MECH_CODE, GSS_C_NULL_OID, &msg_ctx, &status_string);
             if (maj_stat == GSS_S_COMPLETE) {
                 if (sizeof(buf) > len + status_string.length) {
-                    sprintf(buf + len, "%s", (char *) status_string.value);
+                    snprintf(buf + len, (sizeof(buf)-len), "%s", (char *) status_string.value);
                     len += status_string.length;
                 }
                 gss_release_buffer(&min_stat, &status_string);
index 597150bf8f42dc05a0603f9f31b17d87eb15a5bd..5c0acba56a51f8835b2d2d4731c4a3ddea3f8761 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
  *
  */
-
+#define SQUID_NO_ALLOC_PROTECT 1
 #include "config.h"
+
 #include "ntlmauth.h"
 #include "ntlm_smb_lm_auth.h"
-#include "squid_endian.h"
 #include "util.h"
 #include "smbval/smblib-common.h"
 #include "smbval/rfcnb-error.h"
index de91c4574f3c0286c830ec4810be907be185bcf4..138bcfe9d9c0b053994eeed3e996eea8f235ac72 100644 (file)
 #define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
 #define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
 #define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
-#define SVALS(buf,pos) ((int16)SVAL(buf,pos))
-#define IVALS(buf,pos) ((int32)IVAL(buf,pos))
-#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val)))
-#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val)))
-#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
-#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val)))
+#define SVALS(buf,pos) ((int16_t)SVAL(buf,pos))
+#define IVALS(buf,pos) ((int32_t)IVAL(buf,pos))
+#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16_t)(val)))
+#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32_t)(val)))
+#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16_t)(val)))
+#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32_t)(val)))
 #else
 /* this handles things for architectures like the 386 that can handle
  * alignment errors */
  * WARNING: This section is dependent on the length of int16 and int32
  * being correct
  */
-#define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos)))
-#define IVAL(buf,pos) (*(uint32 *)((char *)(buf) + (pos)))
-#define SVALS(buf,pos) (*(int16 *)((char *)(buf) + (pos)))
-#define IVALS(buf,pos) (*(int32 *)((char *)(buf) + (pos)))
-#define SSVAL(buf,pos,val) SVAL(buf,pos)=((uint16)(val))
-#define SIVAL(buf,pos,val) IVAL(buf,pos)=((uint32)(val))
-#define SSVALS(buf,pos,val) SVALS(buf,pos)=((int16)(val))
-#define SIVALS(buf,pos,val) IVALS(buf,pos)=((int32)(val))
+#define SVAL(buf,pos) (*(uint16_t *)((char *)(buf) + (pos)))
+#define IVAL(buf,pos) (*(uint32_t *)((char *)(buf) + (pos)))
+#define SVALS(buf,pos) (*(int16_t *)((char *)(buf) + (pos)))
+#define IVALS(buf,pos) (*(int32_t *)((char *)(buf) + (pos)))
+#define SSVAL(buf,pos,val) SVAL(buf,pos)=((uint16_t)(val))
+#define SIVAL(buf,pos,val) IVAL(buf,pos)=((uint32_t)(val))
+#define SSVALS(buf,pos,val) SVALS(buf,pos)=((int16_t)(val))
+#define SIVALS(buf,pos,val) IVALS(buf,pos)=((int32_t)(val))
 #endif
 
 
index 50a6ce870d3885e3f39633e275f89c45c83bc6d9..20165dc52dca80cf099a88700df0fac3fb583442 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
+#define SQUID_NO_ALLOC_PROTECT 1
+#include "config.h"
 
 #include <string.h>
-#include <stdlib.h>
 
 #include "std-includes.h"
 #include "rfcnb-priv.h"
 #include "rfcnb-io.h"
 #include <arpa/inet.h>
 
-#ifndef uint16
-#ifdef u_int16_t
-typedef u_int16_t uint16;
-#else
-typedef unsigned short uint16;
-#endif
-#endif
-
 extern void (*Prot_Print_Routine) ();  /* Pointer to protocol print routine */
 
 /* Convert name and pad to 16 chars as needed */
index 65776a360270b7430a90640d54aee0e742655ed4..f4346836038a7a735080fcebf60ac1be6481f52e 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
+#define SQUID_NO_ALLOC_PROTECT 1
+#include "config.h"
 
 #include <string.h>
-#include <stdlib.h>
 
 int RFCNB_errno = 0;
 int RFCNB_saved_errno = 0;
@@ -347,14 +348,12 @@ RFCNB_Listen()
 void
 RFCNB_Get_Error(char *buffer, int buf_len)
 {
-
     if (RFCNB_saved_errno <= 0) {
-        sprintf(buffer, "%s", RFCNB_Error_Strings[RFCNB_errno]);
+        snprintf(buffer, buf_len, "%s", RFCNB_Error_Strings[RFCNB_errno]);
     } else {
-        sprintf(buffer, "%s\n\terrno:%s", RFCNB_Error_Strings[RFCNB_errno],
+        snprintf(buffer, buf_len, "%s\n\terrno:%s", RFCNB_Error_Strings[RFCNB_errno],
                 strerror(RFCNB_saved_errno));
     }
-
 }
 
 /* Pick up the last error response and returns as a code                 */
index b25814b1e0f32e097a80911341957c3f20b1808b..c49110902ad4b7c63474609875f36807196c4efd 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
+#define SQUID_NO_ALLOC_PROTECT 1
+#include "config.h"
 
 #include "smblib-priv.h"
-#include <stdlib.h>
 #include <string.h>
 
 #include "rfcnb.h"
@@ -112,7 +113,7 @@ SMB_DOSTimToStr(int DOS_time)
     DOS_month = (DOS_time & 0x01E00000) >> 21;
     DOS_year = ((DOS_time & 0xFE000000) >> 25) + 80;
 
-    sprintf(SMB_Time_Temp, "%2d/%02d/%2d %2d:%02d:%02d", DOS_day, DOS_month,
+    snprintf(SMB_Time_Temp, 48, "%2d/%02d/%2d %2d:%02d:%02d", DOS_day, DOS_month,
             DOS_year, DOS_hour, DOS_min, DOS_sec);
 
     return (SMB_Time_Temp);
index 1e06998c9f0ee6e312b91c44b0862be3c21efe68..ae1dfe59de3a7f486c5eaf6c5bdccf0d081ad3f2 100644 (file)
@@ -23,9 +23,9 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-
+#define SQUID_NO_ALLOC_PROTECT 1
 #include "config.h"
-#include <stdlib.h>
+
 #include <ctype.h>
 #include <string.h>
 
index 4abd92dac66760db247c473b60bfad1a119503de..b51ce23ac1bd6882c50de9a02c5d589a2bfd7ee7 100644 (file)
@@ -209,7 +209,7 @@ public:
     /**
      * Free a element allocated by MemAllocator::alloc()
      */
-    virtual void free(void *) = 0;
+    virtual void freeOne(void *) = 0;
 
     virtual char const *objectType() const;
     virtual size_t objectSize() const = 0;
@@ -259,7 +259,7 @@ public:
     /**
      * Free a element allocated by MemAllocatorProxy::alloc()
      */
-    void free(void *);
+    void freeOne(void *);
 
     int inUseCount() const;
     size_t objectSize() const;
@@ -317,7 +317,7 @@ CLASS::operator new (size_t byteCount) \
 void \
 CLASS::operator delete (void *address) \
 { \
-    Pool().free(address); \
+    Pool().freeOne(address); \
 }
 
 /// \ingroup MemPoolsAPI
@@ -338,7 +338,7 @@ public:
     /**
      * Free a element allocated by MemImplementingAllocator::alloc()
      */
-    virtual void free(void *);
+    virtual void freeOne(void *);
 
     virtual bool idleTrigger(int shift) const = 0;
     virtual void clean(time_t maxage) = 0;
index 7150d4b900caf52efae19ca2aa4e5736683c9ca2..c09b897633eb5291847e284135104b7592929ab3 100644 (file)
@@ -555,7 +555,7 @@ MemImplementingAllocator::alloc()
 }
 
 void
-MemImplementingAllocator::free(void *obj)
+MemImplementingAllocator::freeOne(void *obj)
 {
     assert(obj != NULL);
     (void) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(obj, obj_size);
@@ -882,9 +882,9 @@ MemAllocatorProxy::alloc()
 }
 
 void
-MemAllocatorProxy::free(void *address)
+MemAllocatorProxy::freeOne(void *address)
 {
-    getAllocator()->free(address);
+    getAllocator()->freeOne(address);
     /* TODO: check for empty, and if so, if the default type has altered,
      * switch
      */
index 0e5b7aec5ba9b4daeac20403d131a1405964965f..d026a3ce58b48a45f4272bdaa46d648417cb5bce 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * $Id$
  *
  *
  */
 
-/*
+/**
  * CPU Profiling implementation.
  *
+ * \par
  *  This library implements the Probes needed to gather stats.
  *  See src/ProfStats.c which implements historical recording and
  *  presentation in CacheMgr.cgi.
  *
+ * \par
  *  For timing we prefer on-CPU ops that retrieve cpu ticks counter.
  *  For Intel, this is "rdtsc", which is 64-bit counter that virtually
  *  never wraps. For alpha, this is "rpcc" which is 32-bit counter and
  *   probename must be added to profiling.h into xprof_type enum list
  *   with prepended "XPROF_" string.
  *
- * Description.
- *  PROF gathers stats per probename into structures. It indexes these
+ * \section description Description.
+ * \par PROF
+ *  gathers stats per probename into structures. It indexes these
  *  structures by enum type index in an array.
  *
- *  PROF records best, best, average and worst values for delta time,
+ * \par PROF
+ *  records best, best, average and worst values for delta time,
  *  also, if UNACCED is defined, it measures "empty" time during which
  *  no probes are in measuring state. This allows to see time "unaccounted"
  *  for. If OVERHEAD is defined, additional calculations are made at every
  *  probe to measure approximate overhead of the probe code itself.
  *
+ * \par
  *  Probe data is stored in linked-list, so the more probes you define,
  *  the more overhead is added to find the deepest nested probe. To reduce
  *  average overhead, linked list is manipulated each time PR_start is
  *  fast and frequent sections of code, we want to reduce this overhead
  *  to absolute minimum possible.
  *
+ * \par
  *  For actual measurements, probe overhead cancels out mostly. Still,
  *  do not take the measured times as facts, they should be viewed in
  *  relative comparison to overall CPU time and on the same platform.
  *
+ * \par
  *  Every 1 second, Event within squid is called that parses gathered
  *  statistics of every probe, and accumulates that into historical
  *  structures for last 1,5,30 secs, 1,5,30 mins, and 1,5 and 24 hours.
  *  Each second active probe stats are reset, and only historical data
  *  is presented in cachemgr output.
  *
- * Reading stats.
+ * \section reading Reading stats.
+ * \par
  *  "Worst case" may be misleading. Anything can happen at any section
  *  of code that could delay reaching to probe stop. For eg. system may
  *  need to service interrupt routine, task switch could occur, or page
  *  in given section of code, and its average completion time. This data
  *  could be used to detect bottlenecks withing squid and optimise them.
  *
+ * \par
  *  TOTALS are quite off reality. Its there just to summarise cumulative
  *  times and percent column. Percent values over 100% shows that there
  *  have been some probes nested into each other.
  *
  */
 
-#include "profiling.h"
-
-#include <assert.h>
+#define SQUID_NO_ALLOC_PROTECT 1
+#include "config.h"
 
 #ifdef USE_XPROF_STATS
 
+#include "profiling.h"
 
+#if HAVE_ASSERT_H
+#include <assert.h>
+#endif
 #if HAVE_GNUMALLLOC_H
 #include <gnumalloc.h>
 #elif HAVE_MALLOC_H
index e856c2e795eecb0115d3b34a268075b8257f3ce0..0e75acec502acfa444b5bf43bc0d4ff2f2636527 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * $Id$
  *
@@ -35,6 +34,9 @@
 
 #define _etext etext
 
+/* NP: this file is where the memory allocators are defined. */
+#define SQUID_NO_ALLOC_PROTECT 1
+
 #include "config.h"
 #include "profiling.h"
 
index f4b1337975a077c5584823ff3839df33564988e0..777e807f9c73e117675cecd2cb633ecfcc98a92f 100644 (file)
@@ -21,6 +21,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 SOFTWARE.
 ******************************************************************/
 
+#define SQUID_NO_STRING_BUFFER_PROTECT 1
 #include "config.h"
 
 #include <stdio.h>
index d97be3a7eba310d58d2ce3d8b2917cc43437dc78..d2cc0fd6eecf4e91e1347ae53861386844826370 100644 (file)
@@ -166,7 +166,7 @@ DiskThreadsIOStrategy::callback()
         if (ctrlp->operation == _AIO_READ)
             squidaio_xfree(ctrlp->bufp, ctrlp->len);
 
-        squidaio_ctrl_pool->free(ctrlp);
+        squidaio_ctrl_pool->freeOne(ctrlp);
     }
 
     return retval;
index 6008e7b9f091078785539b9ff8f7fae49171cee5..ca753f7e32badf8282e3c44eec74680771ffd6e4 100644 (file)
@@ -218,7 +218,7 @@ squidaio_xfree(void *p, int size)
     MemAllocator *pool;
 
     if ((pool = squidaio_get_pool(size)) != NULL) {
-        pool->free(p);
+        pool->freeOne(p);
     } else
         xfree(p);
 }
@@ -230,7 +230,7 @@ squidaio_xstrfree(char *str)
     int len = strlen(str) + 1;
 
     if ((pool = squidaio_get_pool(len)) != NULL) {
-        pool->free(str);
+        pool->freeOne(str);
     } else
         xfree(str);
 }
@@ -634,7 +634,7 @@ squidaio_cleanup_request(squidaio_request_t * requestp)
         resultp->aio_errno = requestp->err;
     }
 
-    squidaio_request_pool->free(requestp);
+    squidaio_request_pool->freeOne(requestp);
 }                              /* squidaio_cleanup_request */
 
 
index d0113b468a4d5d07f994c655a2609fb6f1aa56be..f5a6f1c0bc1b68baa6a096a1fe1d646a0fcd4754 100644 (file)
@@ -125,7 +125,7 @@ aioCancel(int fd)
         }
 
         dlinkDelete(m, &used_list);
-        DiskThreadsIOStrategy::Instance.squidaio_ctrl_pool->free(ctrlp);
+        DiskThreadsIOStrategy::Instance.squidaio_ctrl_pool->freeOne(ctrlp);
     }
 }
 
index 9f4494e076062137438bc6d3d69e4fb4e22ec8c2..b222e975ad6098215f2ef9a993d766f45ce473f5 100644 (file)
@@ -99,7 +99,7 @@ template <class MatchType>
 void
 ACLStrategised<MatchType>::operator delete (void *address)
 {
-    Pool->free(address);
+    Pool->freeOne(address);
 }
 
 template <class MatchType>
index a884b62500500ce9fb3d6b487717d5fcdfa41fbc..5006ca3b32577c8293c7174276dde99f87a259e4 100644 (file)
@@ -220,7 +220,7 @@ authenticateDigestNonceDelete(digest_nonce_h * nonce)
 
         safe_free(nonce->key);
 
-        digest_nonce_pool->free(nonce);
+        digest_nonce_pool->freeOne(nonce);
     }
 }
 
index ab5ee3a6e80a6dd26921aa68c85a84f704b890a2..e9515d87fd7ac0c1f98b10bcb319fc71aaea84e6 100644 (file)
@@ -379,10 +379,10 @@ cbdataInternalFree(void *p)
 #if HASHED_CBDATA
     hash_remove_link(cbdata_htable, &c->hash);
     delete c;
-    cbdata_index[theType].pool->free((void *)p);
+    cbdata_index[theType].pool->freeOne((void *)p);
 #else
     c->cbdata::~cbdata();
-    cbdata_index[theType].pool->free(c);
+    cbdata_index[theType].pool->freeOne(c);
 #endif
     return NULL;
 }
@@ -489,10 +489,10 @@ cbdataInternalUnlock(const void *p)
 #if HASHED_CBDATA
     hash_remove_link(cbdata_htable, &c->hash);
     delete c;
-    cbdata_index[theType].pool->free((void *)p);
+    cbdata_index[theType].pool->freeOne((void *)p);
 #else
     c->cbdata::~cbdata();
-    cbdata_index[theType].pool->free(c);
+    cbdata_index[theType].pool->freeOne(c);
 #endif
 }
 
index 9be098844e3e1a196c3a426d5387479418f52dba..cec07ac256377251ca7435b48ea674769aa466ef 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * $Id$
  *
 
 #ifdef USE_POLL
 
+#if HAVE_POLL_H
+#include <poll.h>
+#endif
+
+/* Needed for poll() on Linux at least */
+#if USE_POLL
+#ifndef POLLRDNORM
+#define POLLRDNORM POLLIN
+#endif
+#ifndef POLLWRNORM
+#define POLLWRNORM POLLOUT
+#endif
+#endif
+
 static int MAX_POLL_TIME = 1000;       /* see also comm_quick_poll_required() */
 
 #ifndef        howmany
index 3296dd10630e3706ae2449da394afbe3d4bed51d..6094bb612428ed1d21abc6441612328127e816c4 100644 (file)
@@ -31,7 +31,7 @@ dlinkNodeDelete(dlink_node * m)
     if (m == NULL)
         return;
 
-    dlink_node_pool->free(m);
+    dlink_node_pool->freeOne(m);
 }
 
 void
index b7ff5dc6a602ed2e8ee215d07156657171653e7a..000cfc8ad403bb9e800727adb68f9447e7926304 100644 (file)
@@ -786,7 +786,7 @@ helperStatefulServerFree(int fd, void *data)
     }
 
     if (srv->data != NULL)
-        hlp->datapool->free(srv->data);
+        hlp->datapool->freeOne(srv->data);
 
     cbdataReferenceDone(srv->parent);
 
index b3c269d91519fe40636b75c687990de0dc0dda0a..f947f065d2f6c3d64f8f0be69d73aa4868274cb7 100644 (file)
@@ -639,7 +639,7 @@ htcpFreeSpecifier(htcpSpecifier * s)
 static void
 htcpFreeDetail(htcpDetail * d)
 {
-    htcpDetailPool->free(d);
+    htcpDetailPool->freeOne(d);
 }
 
 /*
index 226712b880aa4f8a9078a7c54d3b66c08c4ab7c1..5e197e94f7c1188879ede73f411f431092d60023 100644 (file)
@@ -186,7 +186,7 @@ memAllocate(mem_type type)
 void
 memFree(void *p, int type)
 {
-    MemPools[type]->free(p);
+    MemPools[type]->freeOne(p);
 }
 
 /* allocate a variable size buffer using best-fit pool */
@@ -241,7 +241,7 @@ memFreeString(size_t size, void *buf)
 
     memMeterDec(StrCountMeter);
     memMeterDel(StrVolumeMeter, size);
-    pool ? pool->free(buf) : xfree(buf);
+    pool ? pool->freeOne(buf) : xfree(buf);
 }
 
 /* Find the best fit MEM_X_BUF type */
index 571d7986993899246763ca8bc92537ef1a49e06f..0b89563fa1f88b6ca2b137444fafa98e138890f1 100644 (file)
@@ -61,7 +61,7 @@ IdleConnList::~IdleConnList()
     parent->unlinkList(this);
 
     if (nfds_alloc == PCONN_FDS_SZ)
-        pconn_fds_pool->free(fds);
+        pconn_fds_pool->freeOne(fds);
     else
         xfree(fds);
 
@@ -118,7 +118,7 @@ IdleConnList::push(int fd)
         xmemcpy(fds, old, nfds * sizeof(int));
 
         if (nfds == PCONN_FDS_SZ)
-            pconn_fds_pool->free(old);
+            pconn_fds_pool->freeOne(old);
         else
             xfree(old);
     }
index b62c4f012ac187de6203cc31d0f1edb53eac005a..893a5a6059fa0a80880a98f6163baa750efa60d4 100644 (file)
@@ -135,7 +135,7 @@ lru_remove(RemovalPolicy * policy, StoreEntry * entry, RemovalPolicyNode * node)
 
     dlinkDelete(&lru_node->node, &lru->list);
 
-    lru_node_pool->free(lru_node);
+    lru_node_pool->freeOne(lru_node);
 
     lru->count -= 1;
 }
@@ -249,7 +249,7 @@ try_again:
         goto try_again;
     }
 
-    lru_node_pool->free(lru_node);
+    lru_node_pool->freeOne(lru_node);
     lru->count -= 1;
     lru->setPolicyNode(entry, NULL);
     return entry;
index 7c6a3ab576ded87107d9067c8ff752ded1267fb9..09e1d3492405c63d6a7b6b56ad029cc7627e75f4 100644 (file)
@@ -52,9 +52,6 @@ using namespace Squid;
 #if HAVE_ERRNO_H
 #include <errno.h>
 #endif
-#if HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
 #if HAVE_GRP_H
 #include <grp.h>
 #endif
@@ -132,114 +129,17 @@ using namespace Squid;
 #ifdef _SQUID_WIN32_
 #include <io.h>
 #endif
-
-#if HAVE_DIRENT_H
-#include <dirent.h>
-#define NAMLEN(dirent) strlen((dirent)->d_name)
-#else /* HAVE_DIRENT_H */
-#define dirent direct
-#define NAMLEN(dirent) (dirent)->d_namlen
-#if HAVE_SYS_NDIR_H
-#include <sys/ndir.h>
-#endif /* HAVE_SYS_NDIR_H */
-#if HAVE_SYS_DIR_H
-#include <sys/dir.h>
-#endif /* HAVE_SYS_DIR_H */
-#if HAVE_NDIR_H
-#include <ndir.h>
-#endif /* HAVE_NDIR_H */
-#endif /* HAVE_DIRENT_H */
-
-#if defined(__QNX__)
-#include <unix.h>
-#endif
-
 #if HAVE_SYS_MOUNT_H
 #include <sys/mount.h>
 #endif
-
-/*
- * We require poll.h before using poll().  If the symbols used
- * by poll() are defined elsewhere, we will need to make this
- * a more sophisticated test.
- *  -- Oskar Pearson <oskar@is.co.za>
- *  -- Stewart Forster <slf@connect.com.au>
- */
-#if USE_POLL
-#if HAVE_POLL_H
-#include <poll.h>
-#endif /* HAVE_POLL_H */
-#endif /* USE_POLL */
-
-
-/*
- * Trap unintentional use of fd_set. Must not be used outside the
- * select code as it only supports FD_SETSIZE number of filedescriptors
- * and Squid may be running with a lot more..
- * But only for code linked into Squid, not the helpers.. (unlinkd, pinger)
- */
-#ifdef SQUID_FDSET_NOUSE
-# ifndef SQUID_HELPER
-#  define fd_set ERROR_FD_SET_USED
-# endif
-#endif
-
 #if HAVE_MATH_H
 #include <math.h>
 #endif
 
-#if 0  // moved to include/rfc2181.h - RFC defined constants
-#define SQUIDHOSTNAMELEN 256
-#endif
-
 #ifndef MAXPATHLEN
 #define MAXPATHLEN SQUID_MAXPATHLEN
 #endif
 
-
-#if !HAVE_STRUCT_RUSAGE
-/*
- * If we don't have getrusage() then we create a fake structure
- * with only the fields Squid cares about.  This just makes the
- * source code cleaner, so we don't need lots of #ifdefs in other
- * places
- */
-
-struct rusage {
-
-    struct timeval ru_stime;
-
-    struct timeval ru_utime;
-    int ru_maxrss;
-    int ru_majflt;
-};
-
-#endif
-
-#if !defined(HAVE_GETPAGESIZE) && defined(_SQUID_HPUX_)
-#define HAVE_GETPAGESIZE
-#define getpagesize( )   sysconf(_SC_PAGE_SIZE)
-#endif
-
-#if defined(_SQUID_MSWIN_) && !defined(getpagesize)
-/* Windows may lack getpagesize() prototype */
-SQUIDCEXTERN size_t getpagesize(void);
-#endif /* _SQUID_MSWIN_ */
-
-#ifndef SA_RESTART
-#define SA_RESTART 0
-#endif
-#ifndef SA_NODEFER
-#define SA_NODEFER 0
-#endif
-#ifndef SA_RESETHAND
-#define SA_RESETHAND 0
-#endif
-#if SA_RESETHAND == 0 && defined(SA_ONESHOT)
-#undef SA_RESETHAND
-#define SA_RESETHAND SA_ONESHOT
-#endif
-
 #if LEAK_CHECK_MODE
 #define LOCAL_ARRAY(type,name,size) \
         static type *local_##name=NULL; \
@@ -259,16 +159,6 @@ SQUIDCEXTERN size_t getpagesize(void);
 #include "ssl_support.h"
 #endif
 
-/* Needed for poll() on Linux at least */
-#if USE_POLL
-#ifndef POLLRDNORM
-#define POLLRDNORM POLLIN
-#endif
-#ifndef POLLWRNORM
-#define POLLWRNORM POLLOUT
-#endif
-#endif
-
 #ifdef SQUID_SNMP
 #include "cache_snmp.h"
 #endif
@@ -306,55 +196,6 @@ SQUIDCEXTERN size_t getpagesize(void);
 #include "protos.h"
 #include "globals.h"
 
-/* Exclude CPPUnit tests from the below restriction. */
-/* BSD implementation uses these still */
-#if !defined(SQUID_UNIT_TEST)
-/*
- * Squid source files should not call these functions directly.
- * Use xmalloc, xfree, xcalloc, snprintf, and xstrdup instead.
- * Also use xmemcpy, xisspace, ...
- */
-#ifndef malloc
-#define malloc +
-#endif
-template <class V>
-void free(V x) { fatal("Do not use ::free()"); }
-#ifndef calloc
-#define calloc +
-#endif
-#ifndef sprintf
-#define sprintf +
-#endif
-#ifndef strdup
-#define strdup +
-#endif
-#endif /* !SQUID_UNIT_TEST */
-
-/*
- * Hey dummy, don't be tempted to move this to lib/config.h.in
- * again.  O_NONBLOCK will not be defined there because you didn't
- * #include <fcntl.h> yet.
- */
-#if defined(_SQUID_SUNOS_)
-/*
- * We assume O_NONBLOCK is broken, or does not exist, on SunOS.
- */
-#define SQUID_NONBLOCK O_NDELAY
-#elif defined(O_NONBLOCK)
-/*
-* We used to assume O_NONBLOCK was broken on Solaris, but evidence
-* now indicates that its fine on Solaris 8, and in fact required for
-* properly detecting EOF on FIFOs.  So now we assume that if
-* its defined, it works correctly on all operating systems.
-*/
-#define SQUID_NONBLOCK O_NONBLOCK
-/*
-* O_NDELAY is our fallback.
-*/
-#else
-#define SQUID_NONBLOCK O_NDELAY
-#endif
-
 /*
  * I'm sick of having to keep doing this ..
  */
index 69b93059dc3842d488d30b107ca687700e319b58..f0f51d053ca3c65b79c02b7eb91009dd4242e376 100644 (file)
@@ -169,7 +169,7 @@ StoreEntry::operator new (size_t bytecount)
 void
 StoreEntry::operator delete (void *address)
 {
-    pool->free(address);
+    pool->freeOne(address);
 }
 
 void
index fdb6f79b85a12d71e33d6c1ac134ae40f1624e40..f44177e305504e0227d89702c5b924df41f3b5c5 100644 (file)
@@ -74,11 +74,11 @@ MemPoolTest::run()
     assert (something);
     assert (something->aValue == 0);
     something->aValue = 5;
-    Pool->free(something);
+    Pool->freeOne(something);
     SomethingToAlloc *otherthing = static_cast<SomethingToAlloc *>(Pool->alloc());
     assert (otherthing == something);
     assert (otherthing->aValue == 0);
-    Pool->free (otherthing);
+    Pool->freeOne(otherthing);
     delete Pool;
 }
 
index a2a93c1bd8d5c86acdb424aa7d3237980a226125..0f6754acfea224fe32d3516bc4e1fb0c92605aa5 100644 (file)
@@ -170,7 +170,7 @@ dlinkNodeDelete(dlink_node * m)
     if (m == NULL)
         return;
 
-    dlink_node_pool->free(m);
+    dlink_node_pool->freeOne(m);
 }
 
 void
index a7fe5005b69bd5c9f244eae59c2ea032af099250..e2a82ca33068d78bd3d4b8d49014711922a57475 100644 (file)
@@ -353,7 +353,7 @@ main(int argc, char *argv[])
         if (newhost) {
             char *t;
             newhost += 3;
-            newhost = strdup(newhost);
+            newhost = xstrdup(newhost);
             t = newhost + strcspn(newhost, "@/?");
             if (*t == '@') {
                 newhost = t + 1;