Skip to content

Commit

Permalink
Added VERIFY_ALL_TALLOC
Browse files Browse the repository at this point in the history
Which walks over the entire talloc'd tree, and does nothing else.
The idea is that if something (i.e. us) over-writes the talloc
headers, then this function will catch it.
  • Loading branch information
alandekok committed Oct 28, 2013
1 parent a03dbdc commit d563be4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/include/libradius.h
Expand Up @@ -619,6 +619,19 @@ int fr_sockaddr2ipaddr(struct sockaddr_storage const *sa, socklen_t salen,
fr_ipaddr_t *ipaddr, int * port);
ssize_t fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inlen);

/*
* Define TALLOC_DEBUG to check overflows with talloc.
* we can't use valgrind, because the memory used by
* talloc is valid memory... just not for us.
*/
#ifdef TALLOC_DEBUG
void fr_talloc_verify_cb(const void *ptr, int depth,
int max_depth, int is_ref,
void *private_data);
#define VERIFY_ALL_TALLOC talloc_report_depth_cb(NULL, 0, -1, fr_talloc_verify_cb, NULL)
#else
#define VERIFY_ALL_TALLOC
#endif

#ifdef WITH_ASCEND_BINARY
/* filters.c */
Expand Down
23 changes: 23 additions & 0 deletions src/lib/misc.c
Expand Up @@ -503,6 +503,21 @@ int ip_hton(char const *src, int af, fr_ipaddr_t *dst)
memset(&hints, 0, sizeof(hints));
hints.ai_family = af;

#ifdef TALLOC_DEBUG
/*
* Avoid malloc for IP addresses. This helps us debug
* memory errors when using talloc.
*/
if (af == AF_INET) {
/*
* If it's all numeric, avoid getaddrinfo()
*/
if (inet_pton(af, src, &dst->ipaddr.ip4addr) == 1) {
return 0;
}
}
#endif

if ((rcode = getaddrinfo(src, NULL, &hints, &res)) != 0) {
fr_strerror_printf("ip_hton: %s", gai_strerror(rcode));
return -1;
Expand Down Expand Up @@ -802,3 +817,11 @@ ssize_t fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inle
return out - start;
}

#ifdef TALLOC_DEBUG
void fr_talloc_verify_cb(UNUSED const void *ptr, UNUSED int depth,
UNUSED int max_depth, UNUSED int is_ref,
UNUSED void *private_data)
{
/* do nothing */
}
#endif
3 changes: 3 additions & 0 deletions src/lib/valuepair.c
Expand Up @@ -80,6 +80,9 @@ static int _pairfree(VALUE_PAIR *vp) {
vp->vp_integer = FREE_MAGIC;
#endif

#ifdef TALLOC_DEBUG
talloc_report_depth_cb(NULL, 0, -1, fr_talloc_verify_cb, NULL);
#endif
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/util.c
Expand Up @@ -189,7 +189,6 @@ void *request_data_reference(REQUEST *request,
return NULL; /* wasn't found, too bad... */
}


/*
* Free a REQUEST struct.
*/
Expand Down Expand Up @@ -229,6 +228,8 @@ void request_free(REQUEST **request_ptr)
#endif
talloc_free(request);
*request_ptr = NULL;

VERIFY_ALL_TALLOC;
}

/*
Expand Down

0 comments on commit d563be4

Please sign in to comment.