------------------------------------------------------------ revno: 10910 revision-id: amosjeffries@squid-cache.org-20101004054322-kfcva59sw2fzknwl parent: squid3@treenet.co.nz-20101003145726-d8ws5pmbh65gj1as committer: Amos Jeffries branch nick: trunk timestamp: Sun 2010-10-03 23:43:22 -0600 message: Updated 3.2 release notes ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: amosjeffries@squid-cache.org-20101004054322-\ # kfcva59sw2fzknwl # target_branch: http://www.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: 3490a85ac9d80225fd860141ba8ea1a58e61c859 # timestamp: 2010-10-04 05:53:39 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20101003145726-\ # d8ws5pmbh65gj1as # # Begin patch === modified file 'compat/Makefile.am' --- compat/Makefile.am 2010-10-03 14:42:04 +0000 +++ compat/Makefile.am 2010-10-04 05:43:22 +0000 @@ -11,16 +11,21 @@ noinst_LIBRARIES = libcompat-squid.a libcompat_squid_a_SOURCES = \ + assert.cc \ assert.h \ + compat.cc \ compat.h \ compat_shared.h \ cpu.h \ + debug.cc \ debug.h \ drand48.h \ eui64_aton.h \ fdsetsize.h \ getaddrinfo.h \ getnameinfo.h \ + GnuRegex.c \ + GnuRegex.h \ inet_ntop.h \ inet_pton.h \ initgroups.h \ @@ -33,6 +38,10 @@ types.h \ unsafe.h \ valgrind.h \ + xalloc.cc \ + xalloc.h \ + xstring.cc \ + xstring.h \ \ os/aix.h \ os/dragonfly.h \ @@ -49,13 +58,7 @@ os/sgi.h \ os/solaris.h \ os/sunos.h \ - os/windows.h \ - \ - assert.cc \ - compat.cc \ - debug.cc \ - GnuRegex.h \ - GnuRegex.c + os/windows.h libcompat_squid_a_LIBADD= $(LIBOBJS) === modified file 'compat/compat.cc' --- compat/compat.cc 2009-01-15 10:53:56 +0000 +++ compat/compat.cc 2010-10-04 05:43:22 +0000 @@ -0,0 +1,4 @@ +#include "config.h" +#include "compat.h" + +void (*failure_notify) (const char *) = NULL; === modified file 'compat/compat_shared.h' --- compat/compat_shared.h 2010-03-25 10:09:56 +0000 +++ compat/compat_shared.h 2010-10-04 05:43:22 +0000 @@ -17,6 +17,17 @@ * of the requirements for wrapping your hack for safe portability. */ +/* + * Define an error display handler override. + * If error_notify is set by the linked program it will be used by the local + * portability functions. Otherwise perror() will be used. + */ +#ifdef __cplusplus +extern "C" +#else +extern +#endif +void (*failure_notify) (const char *); /* * sys/resource.h and sys/time.h are apparently order-dependant. @@ -194,5 +205,11 @@ #endif #endif +/* + * Several function definitions which we provide for security and code safety. + */ +#include "compat/xalloc.h" +#include "compat/xstring.h" + #endif /* _SQUID_COMPAT_SHARED_H */ === added file 'compat/xalloc.cc' --- compat/xalloc.cc 1970-01-01 00:00:00 +0000 +++ compat/xalloc.cc 2010-10-04 05:43:22 +0000 @@ -0,0 +1,105 @@ +#include "config.h" +#include "compat/xalloc.h" + +void * +xcalloc(size_t n, size_t sz) +{ + void *p; + + if (n < 1) + n = 1; + + if (sz < 1) + sz = 1; + + p = calloc(n, sz); + + if (p == NULL) { + if (failure_notify) { + static char msg[128]; + snprintf(msg, 128, "xcalloc: Unable to allocate %u blocks of %u bytes!\n", + (unsigned int) n, (unsigned int) sz); + msg[127] = '\0'; + (*failure_notify) (msg); + } else { + perror("xcalloc"); + } + exit(1); + } + +#if XMALLOC_DEBUG + check_malloc(p, sz * n); +#endif +#if XMALLOC_STATISTICS + malloc_stat(sz * n); +#endif +#if XMALLOC_TRACE + xmalloc_show_trace(p, 1); +#endif +#if MEM_GEN_TRACE + if (tracefp) + fprintf(tracefp, "c:%u:%u:%p\n", (unsigned int) n, (unsigned int) sz, p); +#endif + + return p; +} + +void * +xmalloc(size_t sz) +{ + void *p; + + if (sz < 1) + sz = 1; + + p = malloc(sz); + + if (p == NULL) { + if (failure_notify) { + static char msg[128]; + snprintf(msg, 128, "xmalloc: Unable to allocate %d bytes!\n", + (int) sz); + msg[127] = '\0'; + (*failure_notify) (msg); + } else { + perror("malloc"); + } + exit(1); + } + +#if XMALLOC_DEBUG + check_malloc(p, sz); +#endif +#if XMALLOC_STATISTICS + malloc_stat(sz); +#endif +#if XMALLOC_TRACE + xmalloc_show_trace(p, 1); +#endif +#if MEM_GEN_TRACE + if (tracefp) + fprintf(tracefp, "m:%d:%p\n", sz, p); +#endif + + return (p); +} + +void +xfree(void *s) +{ +#if XMALLOC_TRACE + xmalloc_show_trace(s, -1); +#endif + + if (s != NULL) { +#if XMALLOC_DEBUG + check_free(s); +#endif + free(s); + } + +#if MEM_GEN_TRACE + if (tracefp && s) + fprintf(tracefp, "f:%p\n", s); +#endif +} === added file 'compat/xalloc.h' --- compat/xalloc.h 1970-01-01 00:00:00 +0000 +++ compat/xalloc.h 2010-10-04 05:43:22 +0000 @@ -0,0 +1,39 @@ +#ifndef _SQUID_COMPAT_XALLOC_H +#define _SQUID_COMPAT_XALLOC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * xcalloc() - same as calloc(3). Used for portability. + * Never returns NULL; fatal on error. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +void *xcalloc(size_t n, size_t sz); + +/** + * xmalloc() - same as malloc(3). Used for portability. + * Never returns NULL; fatal on error. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +void *xmalloc(size_t sz); + +/** + * xfree() - same as free(3). Used for portability. + * Will not call free(3) if s == NULL. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +void xfree(void *s); + +#ifdef __cplusplus +} +#endif + +#endif /* _SQUID_COMPAT_XALLOC_H */ === added file 'compat/xstring.cc' --- compat/xstring.cc 1970-01-01 00:00:00 +0000 +++ compat/xstring.cc 2010-10-04 05:43:22 +0000 @@ -0,0 +1,80 @@ +#include "config.h" +#include "compat/xalloc.h" +#include "compat/xstring.h" + +#if HAVE_ERRNO_H +#include +#endif + +char * +xstrdup(const char *s) +{ + size_t sz; + char *p; + + if (s == NULL) { + if (failure_notify) { + (*failure_notify) ("xstrdup: tried to dup a NULL pointer!\n"); + } else { + errno = EINVAL; + perror("xstrdup: tried to dup a NULL pointer!"); + } + exit(1); + } + + /* copy string, including terminating character */ + sz = strlen(s) + 1; + p = (char *)xmalloc(sz); + memcpy(p, s, sz); + + return p; +} + +char * +xstrncpy(char *dst, const char *src, size_t n) +{ + char *r = dst; + + if (!n || !dst) + return dst; + + if (src) + while (--n != 0 && *src != '\0') + *dst++ = *src++; + + *dst = '\0'; + return r; +} + +char * +xstrndup(const char *s, size_t n) +{ + size_t sz; + char *p; + + if (s == NULL) { + errno = EINVAL; + if (failure_notify) { + (*failure_notify) ("xstrndup: tried to dup a NULL pointer!\n"); + } else { + perror("xstrndup: tried to dup a NULL pointer!"); + } + exit(1); + } + if (n < 0) { + errno = EINVAL; + if (failure_notify) { + (*failure_notify) ("xstrndup: tried to dup a negative length string!\n"); + } else { + perror("xstrndup: tried to dup a negative length string!"); + } + exit(1); + } + + sz = strlen(s) + 1; + if (sz > n) + sz = n; + + p = xstrncpy((char *)xmalloc(sz), s, sz); + return p; +} === added file 'compat/xstring.h' --- compat/xstring.h 1970-01-01 00:00:00 +0000 +++ compat/xstring.h 2010-10-04 05:43:22 +0000 @@ -0,0 +1,57 @@ +#ifndef _SQUID_COMPAT_XSTRING_H +#define _SQUID_COMPAT_XSTRING_H + +#if HAVE_STRING_H +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * xstrdup() - same as strdup(3). Used for portability. + * Never returns NULL; fatal on error. + * + * Sets errno to EINVAL if a NULL pointer is passed. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +char *xstrdup(const char *s); + +#ifdef strdup +#undef strdup +#endif +#define strdup(X) xstrdup((X)) + +/* + * xstrncpy() - similar to strncpy(3) but terminates string + * always with '\0' if (n != 0 and dst != NULL), + * and doesn't do padding + */ +char *xstrncpy(char *dst, const char *src, size_t n); + +/** + * xstrndup() - same as strndup(3). Used for portability. + * Never returns NULL; fatal on error. + * + * Sets errno to EINVAL if a NULL pointer or negative + * length is passed. + * + * Define failure_notify to receive error message. + * otherwise perror() is used to display it. + */ +char *xstrndup(const char *s, size_t n); + +#ifdef strndup +#undef strndup +#endif +#define strndup(X) xstrndup((X)) + + +#ifdef __cplusplus +} +#endif + +#endif /* _SQUID_COMPAT_XSTRING_H */ === modified file 'configure.in' --- configure.in 2010-09-23 17:58:15 +0000 +++ configure.in 2010-10-04 05:43:22 +0000 @@ -2112,6 +2112,7 @@ bstring.h \ cassert \ crypt.h \ + cstdlib \ cstring \ ctype.h \ errno.h \ === modified file 'doc/release-notes/release-3.2.sgml' --- doc/release-notes/release-3.2.sgml 2010-09-18 12:55:12 +0000 +++ doc/release-notes/release-3.2.sgml 2010-10-04 05:43:22 +0000 @@ -301,19 +301,22 @@ New tags