Commit 91fbf6ef authored by Andreas Gustafsson's avatar Andreas Gustafsson
Browse files

the new isc_sockaddr_totext() now null terminates the text;

the terminating null is not part of the buffer's used region
parent 84c46a7a
......@@ -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
......
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment