From: Amos Jeffries Date: Mon, 4 Oct 2010 05:43:22 +0000 (-0600) Subject: Updated 3.2 release notes X-Git-Tag: take1~213 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=76a883444f22c69d4fb574cee0b9703083e776f5;p=thirdparty%2Fsquid.git Updated 3.2 release notes --- diff --git a/compat/Makefile.am b/compat/Makefile.am index 03494f72a4..67c1c4b486 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -11,16 +11,21 @@ include $(top_srcdir)/src/Common.am 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 @@ libcompat_squid_a_SOURCES = \ types.h \ unsafe.h \ valgrind.h \ + xalloc.cc \ + xalloc.h \ + xstring.cc \ + xstring.h \ \ os/aix.h \ os/dragonfly.h \ @@ -49,13 +58,7 @@ libcompat_squid_a_SOURCES = \ 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) diff --git a/compat/compat.cc b/compat/compat.cc index e69de29bb2..e36ae43794 100644 --- a/compat/compat.cc +++ b/compat/compat.cc @@ -0,0 +1,4 @@ +#include "config.h" +#include "compat.h" + +void (*failure_notify) (const char *) = NULL; diff --git a/compat/compat_shared.h b/compat/compat_shared.h index 3730b8cd83..84a4515273 100644 --- a/compat/compat_shared.h +++ b/compat/compat_shared.h @@ -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 @@ extern "C" { #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 */ diff --git a/compat/xalloc.cc b/compat/xalloc.cc new file mode 100644 index 0000000000..37de8e8919 --- /dev/null +++ b/compat/xalloc.cc @@ -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 +} diff --git a/compat/xalloc.h b/compat/xalloc.h new file mode 100644 index 0000000000..23d0a5c910 --- /dev/null +++ b/compat/xalloc.h @@ -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 */ diff --git a/compat/xstring.cc b/compat/xstring.cc new file mode 100644 index 0000000000..1e8376cace --- /dev/null +++ b/compat/xstring.cc @@ -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; +} diff --git a/compat/xstring.h b/compat/xstring.h new file mode 100644 index 0000000000..4c8d71ad60 --- /dev/null +++ b/compat/xstring.h @@ -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 */ diff --git a/configure.in b/configure.in index 98c8be27ba..28aedc6ade 100644 --- a/configure.in +++ b/configure.in @@ -2112,6 +2112,7 @@ AC_CHECK_HEADERS( \ bstring.h \ cassert \ crypt.h \ + cstdlib \ cstring \ ctype.h \ errno.h \ diff --git a/doc/release-notes/release-3.2.sgml b/doc/release-notes/release-3.2.sgml index 85f5f2ed34..2082977749 100644 --- a/doc/release-notes/release-3.2.sgml +++ b/doc/release-notes/release-3.2.sgml @@ -301,19 +301,22 @@ This section gives a thorough account of those changes in three categories: New tags