From 91fbf6ef97974c3a9be56f637db69e5b2288647d Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Fri, 29 Oct 1999 23:53:26 +0000 Subject: [PATCH] the new isc_sockaddr_totext() now null terminates the text; the terminating null is not part of the buffer's used region --- lib/isc/include/isc/sockaddr.h | 5 +++-- lib/isc/sockaddr.c | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/isc/include/isc/sockaddr.h b/lib/isc/include/isc/sockaddr.h index 3a9615c161..70ef21cd5d 100644 --- a/lib/isc/include/isc/sockaddr.h +++ b/lib/isc/include/isc/sockaddr.h @@ -76,11 +76,12 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target); /* * Append a text representation of 'sockaddr' to the buffer 'target'. * The text will include both the IP address (v4 or v6) and the port. - * The text is not null terminated. + * The text is null terminated, but the terminating null is not + * part of the buffer's used region. * * Returns: * ISC_R_SUCCESS - * ISC_R_NOSPACE The text did not fit. + * ISC_R_NOSPACE The text or the null termination did not fit. */ ISC_LANG_ENDDECLS diff --git a/lib/isc/sockaddr.c b/lib/isc/sockaddr.c index 1ac08dbfb6..53ed193a0a 100644 --- a/lib/isc/sockaddr.c +++ b/lib/isc/sockaddr.c @@ -135,13 +135,18 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) { plen = strlen(pbuf); isc_buffer_available(target, &avail); - if (alen + 1 + plen < avail.length) + if (alen + 1 + plen + 1 < avail.length) return (ISC_R_NOSPACE); isc_buffer_putmem(target, abuf, alen); isc_buffer_putmem(target, "#", 1); isc_buffer_putmem(target, pbuf, plen); + /* Null terminate after used region. */ + isc_buffer_available(target, &avail); + INSIST(avail.length >= 1); + avail.base[0] = '\0'; + return (ISC_R_SUCCESS); }