[rbldnsd] [PATCH] Fix > 32bit {em,ez,era}alloc memory allocations
Andrew Clayton
andrew at zeta.digital-domain.net
Wed Dec 21 16:20:02 MSK 2016
We were getting out of memory errors when starting rbldnsd. This was
tracked down to erealloc() and thus realloc(3) being called with a size
argument of 0 and thus the realloc call failing.
This was further tracked down to rbldnsd_ip4set.c::ds_ip4set_addent()
as the callee of the failing realloc. For the size argument it is doing
a n * sizeof(struct entry) calculation. In this case we were seeing the
following
268435456 * 16 = 0
size is being passed in as an unsigned int and 268435456 * 16 is
UINT_MAX + 1 = 0.
The simple fix for this is to just pass in the size argument as a size_t
(as is actually specified in the man pages) which will be 8 bytes on 64bit
machines. Which is what we were observing this on.
Indeed using size_t allows rbldnsd to start again. We make this change
to each of malloc/calloc/realloc.
Signed-off-by: Andrew Clayton <andrew at zeta.digital-domain.net>
---
This is in repsonse to Konstantin's message ("Huge zone and out of memory")
rbldnsd.h | 6 +++---
rbldnsd_util.c | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/rbldnsd.h b/rbldnsd.h
index 6acd8a0..f195a30 100644
--- a/rbldnsd.h
+++ b/rbldnsd.h
@@ -367,9 +367,9 @@ extern struct dataset *g_dsacl; /* global acl */
extern const char *show_version; /* version.bind CH TXT */
void oom(void);
-char *emalloc(unsigned size);
-char *ezalloc(unsigned size); /* zero-fill */
-char *erealloc(void *ptr, unsigned size);
+char *emalloc(size_t size);
+char *ezalloc(size_t size); /* zero-fill */
+char *erealloc(void *ptr, size_t size);
char *estrdup(const char *str);
char *ememdup(const void *buf, unsigned size);
diff --git a/rbldnsd_util.c b/rbldnsd_util.c
index d17b51b..c6d628d 100644
--- a/rbldnsd_util.c
+++ b/rbldnsd_util.c
@@ -460,21 +460,21 @@ dump_a_txt(const char *name, const char *rr,
#endif
-char *emalloc(unsigned size) {
+char *emalloc(size_t size) {
void *ptr = malloc(size);
if (!ptr)
oom();
return ptr;
}
-char *ezalloc(unsigned size) {
+char *ezalloc(size_t size) {
void *ptr = calloc(1, size);
if (!ptr)
oom();
return ptr;
}
-char *erealloc(void *ptr, unsigned size) {
+char *erealloc(void *ptr, size_t size) {
void *nptr = realloc(ptr, size);
if (!nptr)
oom();
--
2.7.4
More information about the rbldnsd
mailing list