Adam Tkac ce30f7
Index: lib/isc/mem.c
Adam Tkac ce30f7
===================================================================
Adam Tkac ce30f7
RCS file: /var/snap/bind9/lib/isc/mem.c,v
Adam Tkac ce30f7
retrieving revision 1.145
Adam Tkac ce30f7
retrieving revision 1.145.120.4
Adam Tkac ce30f7
diff -u -p -r1.145 -r1.145.120.4
Adam Tkac ce30f7
--- lib/isc/mem.c	2 Apr 2008 02:37:42 -0000	1.145
Adam Tkac ce30f7
+++ lib/isc/mem.c	16 Feb 2009 03:17:05 -0000	1.145.120.4
Adam Tkac ce30f7
@@ -1,5 +1,5 @@
Adam Tkac ce30f7
 /*
Adam Tkac ce30f7
- * Copyright (C) 2004-2008  Internet Systems Consortium, Inc. ("ISC")
Adam Tkac ce30f7
+ * Copyright (C) 2004-2009  Internet Systems Consortium, Inc. ("ISC")
Adam Tkac ce30f7
  * Copyright (C) 1997-2003  Internet Software Consortium.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  * Permission to use, copy, modify, and/or distribute this software for any
Adam Tkac ce30f7
@@ -15,7 +15,7 @@
Adam Tkac ce30f7
  * PERFORMANCE OF THIS SOFTWARE.
Adam Tkac ce30f7
  */
Adam Tkac ce30f7
 
Adam Tkac ce30f7
-/* $Id: bind-96-realloc.patch,v 1.1 2009/03/04 09:27:48 atkac Exp $ */
Adam Tkac ce30f7
+/* $Id: bind-96-realloc.patch,v 1.1 2009/03/04 09:27:48 atkac Exp $ */
Adam Tkac ce30f7
 
Adam Tkac ce30f7
 /*! \file */
Adam Tkac ce30f7
 
Adam Tkac ce30f7
@@ -52,7 +52,7 @@ LIBISC_EXTERNAL_DATA unsigned int isc_me
Adam Tkac ce30f7
 
Adam Tkac ce30f7
 #define DEF_MAX_SIZE		1100
Adam Tkac ce30f7
 #define DEF_MEM_TARGET		4096
Adam Tkac ce30f7
-#define ALIGNMENT_SIZE		8		/*%< must be a power of 2 */
Adam Tkac ce30f7
+#define ALIGNMENT_SIZE		8U		/*%< must be a power of 2 */
Adam Tkac ce30f7
 #define NUM_BASIC_BLOCKS	64		/*%< must be > 1 */
Adam Tkac ce30f7
 #define TABLE_INCREMENT		1024
Adam Tkac ce30f7
 #define DEBUGLIST_COUNT		1024
Adam Tkac ce30f7
@@ -1191,7 +1191,7 @@ print_active(isc_mem_t *mctx, FILE *out)
Adam Tkac ce30f7
 		const char *format;
Adam Tkac ce30f7
 		isc_boolean_t found;
Adam Tkac ce30f7
 
Adam Tkac ce30f7
-		fprintf(out, isc_msgcat_get(isc_msgcat, ISC_MSGSET_MEM,
Adam Tkac ce30f7
+		fprintf(out, "%s", isc_msgcat_get(isc_msgcat, ISC_MSGSET_MEM,
Adam Tkac ce30f7
 					    ISC_MSG_DUMPALLOC,
Adam Tkac ce30f7
 					    "Dump of all outstanding "
Adam Tkac ce30f7
 					    "memory allocations:\n"));
Adam Tkac ce30f7
@@ -1217,7 +1217,7 @@ print_active(isc_mem_t *mctx, FILE *out)
Adam Tkac ce30f7
 			}
Adam Tkac ce30f7
 		}
Adam Tkac ce30f7
 		if (!found)
Adam Tkac ce30f7
-			fprintf(out, isc_msgcat_get(isc_msgcat, ISC_MSGSET_MEM,
Adam Tkac ce30f7
+			fprintf(out, "%s", isc_msgcat_get(isc_msgcat, ISC_MSGSET_MEM,
Adam Tkac ce30f7
 						    ISC_MSG_NONE, "\tNone.\n"));
Adam Tkac ce30f7
 	}
Adam Tkac ce30f7
 }
Adam Tkac ce30f7
@@ -1259,7 +1259,7 @@ isc_mem_stats(isc_mem_t *ctx, FILE *out)
Adam Tkac ce30f7
 	 */
Adam Tkac ce30f7
 	pool = ISC_LIST_HEAD(ctx->pools);
Adam Tkac ce30f7
 	if (pool != NULL) {
Adam Tkac ce30f7
-		fprintf(out, isc_msgcat_get(isc_msgcat, ISC_MSGSET_MEM,
Adam Tkac ce30f7
+		fprintf(out, "%s", isc_msgcat_get(isc_msgcat, ISC_MSGSET_MEM,
Adam Tkac ce30f7
 					    ISC_MSG_POOLSTATS,
Adam Tkac ce30f7
 					    "[Pool statistics]\n"));
Adam Tkac ce30f7
 		fprintf(out, "%15s %10s %10s %10s %10s %10s %10s %10s %1s\n",
Adam Tkac ce30f7
@@ -1365,6 +1365,40 @@ isc__mem_allocate(isc_mem_t *ctx, size_t
Adam Tkac ce30f7
 	return (si);
Adam Tkac ce30f7
 }
Adam Tkac ce30f7
 
Adam Tkac ce30f7
+void *
Adam Tkac ce30f7
+isc__mem_reallocate(isc_mem_t *ctx, void *ptr, size_t size FLARG) {
Adam Tkac ce30f7
+	void *new_ptr = NULL;
Adam Tkac ce30f7
+	size_t oldsize, copysize;
Adam Tkac ce30f7
+
Adam Tkac ce30f7
+	REQUIRE(VALID_CONTEXT(ctx));
Adam Tkac ce30f7
+
Adam Tkac ce30f7
+	/*
Adam Tkac ce30f7
+	 * This function emulates the realloc(3) standard library function:
Adam Tkac ce30f7
+	 * - if size > 0, allocate new memory; and if ptr is non NULL, copy
Adam Tkac ce30f7
+	 *   as much of the old contents to the new buffer and free the old one.
Adam Tkac ce30f7
+	 *   Note that when allocation fails the original pointer is intact;
Adam Tkac ce30f7
+	 *   the caller must free it.
Adam Tkac ce30f7
+	 * - if size is 0 and ptr is non NULL, simply free the given ptr.
Adam Tkac ce30f7
+	 * - this function returns:
Adam Tkac ce30f7
+	 *     pointer to the newly allocated memory, or
Adam Tkac ce30f7
+	 *     NULL if allocation fails or doesn't happen.
Adam Tkac ce30f7
+	 */
Adam Tkac ce30f7
+	if (size > 0U) {
Adam Tkac ce30f7
+		new_ptr = isc__mem_allocate(ctx, size FLARG_PASS);
Adam Tkac ce30f7
+		if (new_ptr != NULL && ptr != NULL) {
Adam Tkac ce30f7
+			oldsize = (((size_info *)ptr)[-1]).u.size;
Adam Tkac ce30f7
+			INSIST(oldsize >= ALIGNMENT_SIZE);
Adam Tkac ce30f7
+			oldsize -= ALIGNMENT_SIZE;
Adam Tkac ce30f7
+			copysize = oldsize > size ? size : oldsize;
Adam Tkac ce30f7
+			memcpy(new_ptr, ptr, copysize);
Adam Tkac ce30f7
+			isc__mem_free(ctx, ptr FLARG_PASS);
Adam Tkac ce30f7
+		}
Adam Tkac ce30f7
+	} else if (ptr != NULL)
Adam Tkac ce30f7
+		isc__mem_free(ctx, ptr FLARG_PASS);
Adam Tkac ce30f7
+
Adam Tkac ce30f7
+	return (new_ptr);
Adam Tkac ce30f7
+}
Adam Tkac ce30f7
+
Adam Tkac ce30f7
 void
Adam Tkac ce30f7
 isc__mem_free(isc_mem_t *ctx, void *ptr FLARG) {
Adam Tkac ce30f7
 	size_info *si;
Adam Tkac ce30f7
Index: lib/isc/include/isc/mem.h
Adam Tkac ce30f7
===================================================================
Adam Tkac ce30f7
RCS file: /var/snap/bind9/lib/isc/include/isc/mem.h,v
Adam Tkac ce30f7
retrieving revision 1.78
Adam Tkac ce30f7
retrieving revision 1.78.120.3
Adam Tkac ce30f7
diff -u -p -r1.78 -r1.78.120.3
Adam Tkac ce30f7
--- lib/isc/include/isc/mem.h	31 Mar 2008 05:00:30 -0000	1.78
Adam Tkac ce30f7
+++ lib/isc/include/isc/mem.h	11 Feb 2009 03:07:01 -0000	1.78.120.3
Adam Tkac ce30f7
@@ -1,5 +1,5 @@
Adam Tkac ce30f7
 /*
Adam Tkac ce30f7
- * Copyright (C) 2004-2008  Internet Systems Consortium, Inc. ("ISC")
Adam Tkac ce30f7
+ * Copyright (C) 2004-2009  Internet Systems Consortium, Inc. ("ISC")
Adam Tkac ce30f7
  * Copyright (C) 1997-2001  Internet Software Consortium.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  * Permission to use, copy, modify, and/or distribute this software for any
Adam Tkac ce30f7
@@ -15,7 +15,7 @@
Adam Tkac ce30f7
  * PERFORMANCE OF THIS SOFTWARE.
Adam Tkac ce30f7
  */
Adam Tkac ce30f7
 
Adam Tkac ce30f7
-/* $Id: bind-96-realloc.patch,v 1.1 2009/03/04 09:27:48 atkac Exp $ */
Adam Tkac ce30f7
+/* $Id: bind-96-realloc.patch,v 1.1 2009/03/04 09:27:48 atkac Exp $ */
Adam Tkac ce30f7
 
Adam Tkac ce30f7
 #ifndef ISC_MEM_H
Adam Tkac ce30f7
 #define ISC_MEM_H 1
Adam Tkac ce30f7
@@ -94,7 +94,7 @@ LIBISC_EXTERNAL_DATA extern unsigned int
Adam Tkac ce30f7
 /*!<
Adam Tkac ce30f7
  * The variable isc_mem_debugging holds a set of flags for
Adam Tkac ce30f7
  * turning certain memory debugging options on or off at
Adam Tkac ce30f7
- * runtime.  Its is intialized to the value ISC_MEM_DEGBUGGING,
Adam Tkac ce30f7
+ * runtime.  It is initialized to the value ISC_MEM_DEGBUGGING,
Adam Tkac ce30f7
  * which is 0 by default but may be overridden at compile time.
Adam Tkac ce30f7
  * The following flags can be specified:
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
@@ -106,7 +106,7 @@ LIBISC_EXTERNAL_DATA extern unsigned int
Adam Tkac ce30f7
  *	Crash if a free doesn't match an allocation.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  * \li #ISC_MEM_DEBUGUSAGE
Adam Tkac ce30f7
- *	If a hi_water mark is set, print the maximium inuse memory
Adam Tkac ce30f7
+ *	If a hi_water mark is set, print the maximum inuse memory
Adam Tkac ce30f7
  *	every time it is raised once it exceeds the hi_water mark.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  * \li #ISC_MEM_DEBUGSIZE
Adam Tkac ce30f7
@@ -154,11 +154,12 @@ LIBISC_EXTERNAL_DATA extern unsigned int
Adam Tkac ce30f7
 
Adam Tkac ce30f7
 #define isc_mem_get(c, s)	isc__mem_get((c), (s) _ISC_MEM_FILELINE)
Adam Tkac ce30f7
 #define isc_mem_allocate(c, s)	isc__mem_allocate((c), (s) _ISC_MEM_FILELINE)
Adam Tkac ce30f7
+#define isc_mem_reallocate(c, p, s) isc__mem_reallocate((c), (p), (s) _ISC_MEM_FILELINE)
Adam Tkac ce30f7
 #define isc_mem_strdup(c, p)	isc__mem_strdup((c), (p) _ISC_MEM_FILELINE)
Adam Tkac ce30f7
 #define isc_mempool_get(c)	isc__mempool_get((c) _ISC_MEM_FILELINE)
Adam Tkac ce30f7
 
Adam Tkac ce30f7
 /*%
Adam Tkac ce30f7
- * isc_mem_putanddetach() is a convienence function for use where you
Adam Tkac ce30f7
+ * isc_mem_putanddetach() is a convenience function for use where you
Adam Tkac ce30f7
  * have a structure with an attached memory context.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  * Given:
Adam Tkac ce30f7
@@ -341,12 +342,12 @@ isc_mem_setwater(isc_mem_t *mctx, isc_me
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  * When the memory usage of 'mctx' exceeds 'hiwater',
Adam Tkac ce30f7
  * '(water)(water_arg, #ISC_MEM_HIWATER)' will be called.  'water' needs to
Adam Tkac ce30f7
- * call isc_mem_waterack() with #ISC_MEM_HIWATER to acknowlege the state
Adam Tkac ce30f7
+ * call isc_mem_waterack() with #ISC_MEM_HIWATER to acknowledge the state
Adam Tkac ce30f7
  * change.  'water' may be called multiple times.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  * When the usage drops below 'lowater', 'water' will again be called, this
Adam Tkac ce30f7
  * time with #ISC_MEM_LOWATER.  'water' need to calls isc_mem_waterack() with
Adam Tkac ce30f7
- * #ISC_MEM_LOWATER to acknowlege the change.
Adam Tkac ce30f7
+ * #ISC_MEM_LOWATER to acknowledge the change.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  *	static void
Adam Tkac ce30f7
  *	water(void *arg, int mark) {
Adam Tkac ce30f7
@@ -373,7 +374,7 @@ isc_mem_setwater(isc_mem_t *mctx, isc_me
Adam Tkac ce30f7
 void
Adam Tkac ce30f7
 isc_mem_waterack(isc_mem_t *ctx, int mark);
Adam Tkac ce30f7
 /*%<
Adam Tkac ce30f7
- * Called to acknowledge changes in signalled by calls to 'water'.
Adam Tkac ce30f7
+ * Called to acknowledge changes in signaled by calls to 'water'.
Adam Tkac ce30f7
  */
Adam Tkac ce30f7
 
Adam Tkac ce30f7
 void
Adam Tkac ce30f7
@@ -512,7 +513,7 @@ isc_mempool_associatelock(isc_mempool_t 
Adam Tkac ce30f7
  * and it is also used to set or get internal state via the isc_mempool_get*()
Adam Tkac ce30f7
  * and isc_mempool_set*() set of functions.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
- * Mutiple pools can each share a single lock.  For instance, if "manager"
Adam Tkac ce30f7
+ * Multiple pools can each share a single lock.  For instance, if "manager"
Adam Tkac ce30f7
  * type object contained pools for various sizes of events, and each of
Adam Tkac ce30f7
  * these pools used a common lock.  Note that this lock must NEVER be used
Adam Tkac ce30f7
  * by other than mempool routines once it is given to a pool, since that can
Adam Tkac ce30f7
@@ -612,6 +613,8 @@ void
Adam Tkac ce30f7
 isc__mem_put(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);
Adam Tkac ce30f7
 void *
Adam Tkac ce30f7
 isc__mem_allocate(isc_mem_t *, size_t _ISC_MEM_FLARG);
Adam Tkac ce30f7
+void *
Adam Tkac ce30f7
+isc__mem_reallocate(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);
Adam Tkac ce30f7
 void
Adam Tkac ce30f7
 isc__mem_free(isc_mem_t *, void * _ISC_MEM_FLARG);
Adam Tkac ce30f7
 char *
Adam Tkac ce30f7
Index: lib/dns/openssl_link.c
Adam Tkac ce30f7
===================================================================
Adam Tkac ce30f7
RCS file: /var/snap/bind9/lib/dns/openssl_link.c,v
Adam Tkac ce30f7
retrieving revision 1.22
Adam Tkac ce30f7
retrieving revision 1.22.112.3
Adam Tkac ce30f7
diff -u -p -r1.22 -r1.22.112.3
Adam Tkac ce30f7
--- lib/dns/openssl_link.c	5 Apr 2008 23:47:11 -0000	1.22
Adam Tkac ce30f7
+++ lib/dns/openssl_link.c	11 Feb 2009 03:07:01 -0000	1.22.112.3
Adam Tkac ce30f7
@@ -1,5 +1,5 @@
Adam Tkac ce30f7
 /*
Adam Tkac ce30f7
- * Portions Copyright (C) 2004-2008  Internet Systems Consortium, Inc. ("ISC")
Adam Tkac ce30f7
+ * Portions Copyright (C) 2004-2009  Internet Systems Consortium, Inc. ("ISC")
Adam Tkac ce30f7
  * Portions Copyright (C) 1999-2003  Internet Software Consortium.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  * Permission to use, copy, modify, and/or distribute this software for any
Adam Tkac ce30f7
@@ -31,7 +31,7 @@
Adam Tkac ce30f7
 
Adam Tkac ce30f7
 /*
Adam Tkac ce30f7
  * Principal Author: Brian Wellington
Adam Tkac ce30f7
- * $Id: bind-96-realloc.patch,v 1.1 2009/03/04 09:27:48 atkac Exp $
Adam Tkac ce30f7
+ * $Id: bind-96-realloc.patch,v 1.1 2009/03/04 09:27:48 atkac Exp $
Adam Tkac ce30f7
  */
Adam Tkac ce30f7
 #ifdef OPENSSL
Adam Tkac ce30f7
 
Adam Tkac ce30f7
@@ -148,18 +148,8 @@ mem_free(void *ptr) {
Adam Tkac ce30f7
 
Adam Tkac ce30f7
 static void *
Adam Tkac ce30f7
 mem_realloc(void *ptr, size_t size) {
Adam Tkac ce30f7
-	void *p;
Adam Tkac ce30f7
-
Adam Tkac ce30f7
 	INSIST(dst__memory_pool != NULL);
Adam Tkac ce30f7
-	p = NULL;
Adam Tkac ce30f7
-	if (size > 0U) {
Adam Tkac ce30f7
-		p = mem_alloc(size);
Adam Tkac ce30f7
-		if (p != NULL && ptr != NULL)
Adam Tkac ce30f7
-			memcpy(p, ptr, size);
Adam Tkac ce30f7
-	}
Adam Tkac ce30f7
-	if (ptr != NULL)
Adam Tkac ce30f7
-		mem_free(ptr);
Adam Tkac ce30f7
-	return (p);
Adam Tkac ce30f7
+	return (isc_mem_reallocate(dst__memory_pool, ptr, size));
Adam Tkac ce30f7
 }
Adam Tkac ce30f7
 
Adam Tkac ce30f7
 isc_result_t
Adam Tkac ce30f7
@@ -252,7 +242,7 @@ dst__openssl_init() {
Adam Tkac ce30f7
 		for (e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e)) {
Adam Tkac ce30f7
 
Adam Tkac ce30f7
 			/*
Adam Tkac ce30f7
-			 * Something wierd here. If we call ENGINE_finish()
Adam Tkac ce30f7
+			 * Something weird here. If we call ENGINE_finish()
Adam Tkac ce30f7
 			 * ENGINE_get_default_RAND() will fail.
Adam Tkac ce30f7
 			 */
Adam Tkac ce30f7
 			if (ENGINE_init(e)) {
Adam Tkac ce30f7
@@ -386,7 +376,7 @@ dst__openssl_setdefault(const char *name
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  * 'engine_id' is the openssl engine name.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
- * pre_cmds and post_cmds a sequence if command arguement pairs
Adam Tkac ce30f7
+ * pre_cmds and post_cmds a sequence if command argument pairs
Adam Tkac ce30f7
  * pre_num and post_num are a count of those pairs.
Adam Tkac ce30f7
  *
Adam Tkac ce30f7
  * "SO_PATH", PKCS11_SO_PATH ("/usr/local/lib/engines/engine_pkcs11.so")