]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix unknown extended rcodes in dig
authorFrancis Dupont <fdupont@isc.org>
Wed, 6 May 2009 10:21:00 +0000 (10:21 +0000)
committerFrancis Dupont <fdupont@isc.org>
Wed, 6 May 2009 10:21:00 +0000 (10:21 +0000)
CHANGES
bin/dig/dig.c
bin/dig/host.c
bin/dig/nslookup.c

diff --git a/CHANGES b/CHANGES
index 9ed9f0b415fdbe09820db232e7ef1f6b049a182b..b41ab64fbffa63a6755eb9878e2f2c3e56586ec9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+2595.  [bug]           Fix unknown extended rcodes in dig. [RT #19625]
+
 2592.  [bug]           Treat "any" as a type in nsupdate. [RT #19455]
 
 2591.  [bug]           named could die when processing a update in
index 22ec509877fc56cb9fbae87d0c9f359bcc61fe5d..4cc40c3942312e2c241037c8718b4e154aaaabe1 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dig.c,v 1.186.18.36 2009/01/22 05:14:05 marka Exp $ */
+/* $Id: dig.c,v 1.186.18.37 2009/05/06 10:21:00 fdupont Exp $ */
 
 /*! \file */
 
@@ -111,6 +111,24 @@ static const char * const rcodetext[] = {
        "BADVERS"
 };
 
+/*% safe rcodetext[] */
+static char *
+rcode_totext(dns_rcode_t rcode)
+{
+       static char buf[sizeof("?65535")];
+       union {
+               const char *consttext;
+               char *deconsttext;
+       } totext;
+
+       if (rcode >= (sizeof(rcodetext)/sizeof(rcodetext[0]))) {
+               snprintf(buf, sizeof(buf), "?%u", rcode);
+               totext.deconsttext = buf;
+       } else
+               totext.consttext = rcodetext[rcode];
+       return totext.deconsttext;
+}
+
 /*% print usage */
 static void
 print_usage(FILE *fp) {
@@ -468,7 +486,8 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
                if (headers) {
                        printf(";; ->>HEADER<<- opcode: %s, status: %s, "
                               "id: %u\n",
-                              opcodetext[msg->opcode], rcodetext[msg->rcode],
+                              opcodetext[msg->opcode],
+                              rcode_totext(msg->rcode),
                               msg->id);
                        printf(";; flags:");
                        if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0)
index 33025d5307e5f5c22997f91ba58e429c0e8242a2..00c8eb17a6d9f8b5e1281b0c26bf7cc9c3be036e 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: host.c,v 1.94.18.19 2007/08/28 07:19:55 tbox Exp $ */
+/* $Id: host.c,v 1.94.18.20 2009/05/06 10:21:00 fdupont Exp $ */
 
 /*! \file */
 
@@ -124,6 +124,23 @@ struct rtype rtypes[] = {
        { 0, NULL }
 };
 
+static char *
+rcode_totext(dns_rcode_t rcode)
+{
+       static char buf[sizeof("?65535")];
+       union {
+               const char *consttext;
+               char *deconsttext;
+       } totext;
+
+       if (rcode >= (sizeof(rcodetext)/sizeof(rcodetext[0]))) {
+               snprintf(buf, sizeof(buf), "?%u", rcode);
+               totext.deconsttext = buf;
+       } else
+               totext.consttext = rcodetext[rcode];
+       return totext.deconsttext;
+}
+
 static void
 show_usage(void) {
        fputs(
@@ -429,7 +446,7 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
                printf("Host %s not found: %d(%s)\n",
                       (msg->rcode != dns_rcode_nxdomain) ? namestr :
                       query->lookup->textname, msg->rcode,
-                      rcodetext[msg->rcode]);
+                      rcode_totext(msg->rcode));
                return (ISC_R_SUCCESS);
        }
 
@@ -471,7 +488,7 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
 
        if (!short_form) {
                printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n",
-                      opcodetext[msg->opcode], rcodetext[msg->rcode],
+                      opcodetext[msg->opcode], rcode_totext(msg->rcode),
                       msg->id);
                printf(";; flags: ");
                if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
index ab0eea9fcd7683b6b53843b21060bb21717d65aa..8ea3eaaf3dfcf5e14b55e97fbfa5f8d559dd01cb 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: nslookup.c,v 1.101.18.17 2008/12/16 23:46:02 tbox Exp $ */
+/* $Id: nslookup.c,v 1.101.18.18 2009/05/06 10:21:00 fdupont Exp $ */
 
 #include <config.h>
 
@@ -129,6 +129,23 @@ static const char *rtypetext[] = {
 static void flush_lookup_list(void);
 static void getinput(isc_task_t *task, isc_event_t *event);
 
+static char *
+rcode_totext(dns_rcode_t rcode)
+{
+       static char buf[sizeof("?65535")];
+       union {
+               const char *consttext;
+               char *deconsttext;
+       } totext;
+
+       if (rcode >= (sizeof(rcodetext)/sizeof(rcodetext[0]))) {
+               snprintf(buf, sizeof(buf), "?%u", rcode);
+               totext.deconsttext = buf;
+       } else
+               totext.consttext = rcodetext[rcode];
+       return totext.deconsttext;
+}
+
 void
 dighost_shutdown(void) {
        isc_event_t *event = global_event;
@@ -412,7 +429,7 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
                                nametext, sizeof(nametext));
                printf("** server can't find %s: %s\n",
                       (msg->rcode != dns_rcode_nxdomain) ? nametext :
-                      query->lookup->textname, rcodetext[msg->rcode]);
+                      query->lookup->textname, rcode_totext(msg->rcode));
                debug("returning with rcode == 0");
                return (ISC_R_SUCCESS);
        }