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

diff --git a/CHANGES b/CHANGES
index 889e6b3fb8c7c2932e405d1075a89d40055e0c10..04d5e01b6a8722e0040df45dcf66ff2468201409 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 87c40d70508d9a20fc8dc2817cf9275b913b3202..f740a1d629669ebcbfc891fa5eb9869cda00495b 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dig.c,v 1.225.26.3 2009/01/22 05:19:47 marka Exp $ */
+/* $Id: dig.c,v 1.225.26.4 2009/05/06 10:18:33 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) {
@@ -469,7 +487,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 ac29ae6c70d0ca204f615ac12e0872cb5f4e9dae..1ed941549f645cefb04f70515003e58e893bcc9f 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: host.c,v 1.116 2007/12/03 00:21:48 marka Exp $ */
+/* $Id: host.c,v 1.116.216.1 2009/05/06 10:18:33 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 b17032ff75fd79d30ca5015dd3f8a0a90a23c629..77e8946714dc5a0878c0fb40af24ef9deade22cb 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: nslookup.c,v 1.117.334.2 2009/01/06 23:47:26 tbox Exp $ */
+/* $Id: nslookup.c,v 1.117.334.3 2009/05/06 10:18:33 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);
        }