mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-09 13:42:06 -04:00
the new isc_sockaddr_totext() now null terminates the text;
the terminating null is not part of the buffer's used region
This commit is contained in:
parent
84c46a7acb
commit
91fbf6ef97
2 changed files with 9 additions and 3 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue