From 6883a918f790147fd98e21b2c3d3d479320f3ed5 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 21 Feb 2011 06:50:42 +0000 Subject: [PATCH] 3031. [bug] dns_rdataclass_format() handle a zero sized buffer. [RT #22521] --- CHANGES | 3 +++ lib/dns/rcode.c | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index e8455e47eb..dd831c7b43 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +3031. [bug] dns_rdataclass_format() handle a zero sized buffer. + [RT #22521] + 3030. [bug] dns_rdatatype_format() handle a zero sized buffer. [RT #22521] diff --git a/lib/dns/rcode.c b/lib/dns/rcode.c index fd9d2fe0d3..d8c07cb589 100644 --- a/lib/dns/rcode.c +++ b/lib/dns/rcode.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rcode.c,v 1.16 2010/12/23 04:07:58 marka Exp $ */ +/* $Id: rcode.c,v 1.17 2011/02/21 06:50:42 marka Exp $ */ #include #include @@ -494,6 +494,9 @@ dns_rdataclass_format(dns_rdataclass_t rdclass, isc_result_t result; isc_buffer_t buf; + if (size == 0U) + return; + isc_buffer_init(&buf, array, size); result = dns_rdataclass_totext(rdclass, &buf); /* @@ -505,8 +508,6 @@ dns_rdataclass_format(dns_rdataclass_t rdclass, else result = ISC_R_NOSPACE; } - if (result != ISC_R_SUCCESS) { - snprintf(array, size, ""); - array[size - 1] = '\0'; - } + if (result != ISC_R_SUCCESS) + strlcpy(array, "", size); }