aboutsummaryrefslogtreecommitdiffstats
path: root/common/estream-printf.h
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2012-01-20 13:27:36 +0000
committerWerner Koch <[email protected]>2012-01-20 13:27:36 +0000
commite97e2ced6cf3ee295a3cc9f8968969a1910380ea (patch)
treea93dc002b07e86f218886d3a08f06ecece0f09c6 /common/estream-printf.h
parentDo not copy default merge commit log entries into the ChangeLog. (diff)
downloadgnupg-e97e2ced6cf3ee295a3cc9f8968969a1910380ea.tar.gz
gnupg-e97e2ced6cf3ee295a3cc9f8968969a1910380ea.zip
estream: Fix unclean usage of realloc.
* common/estream-printf.c (_ESTREAM_PRINTF_MALLOC): Remove. (_ESTREAM_PRINTF_FREE): Remove. (_ESTREAM_PRINTF_REALLOC): New. (fixed_realloc) [!_ESTREAM_PRINTF_REALLOC]): New. (estream_vasprintf): Use my_printf_realloc instead of my_printf_malloc and my_printf_free. (dynamic_buffer_out): Use my_printf_realloc instead of realloc. -- This bug will never happen in current GnuPG/Libgcrypt because we use the standard memory allocation functions via Libgcrypt. However, when used in other environments it would mess up the heap for an asprintf with an output length larger than ~512 bytes.
Diffstat (limited to 'common/estream-printf.h')
-rw-r--r--common/estream-printf.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/common/estream-printf.h b/common/estream-printf.h
index 9b6b83810..1aaad7812 100644
--- a/common/estream-printf.h
+++ b/common/estream-printf.h
@@ -1,5 +1,5 @@
/* estream-printf.h - Versatile mostly C-99 compliant printf formatting.
- * Copyright (C) 2007, 2010 g10 Code GmbH
+ * Copyright (C) 2007, 2010, 2012 g10 Code GmbH
*
* This file is part of Libestream.
*
@@ -66,12 +66,13 @@
For the implementation of the code (estream-printf.c) the following
macros may be used to tune the implementation for certain systems:
- #define _ESTREAM_PRINTF_MALLOC foo_malloc
- #define _ESTREAM_PRINTF_FREE foo_free
+ #define _ESTREAM_PRINTF_REALLOC foo_realloc
- Make estream_asprintf and estream_vasprintf use foo_malloc and
- foo_free instead of the standard malloc and free functions to
- allocate the memory returned to the caller.
+ Make estream_asprintf and estream_vasprintf use foo_realloc
+ instead of the standard realloc to allocate memory returned to
+ the caller. Note that foo_realloc needs to be C-90 compliant:
+ foo_realloc (NULL,n) is the same as a call to malloc(n) and
+ foo_realloc (a, 0) is the same as a call to free (a).
#define _ESTREAM_PRINTF_EXTRA_INCLUDE "foo.h"