]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
3438. [bug] Don't accept unknown data escape in quotes. [RT #32031]
authorMark Andrews <marka@isc.org>
Sat, 8 Dec 2012 03:05:32 +0000 (14:05 +1100)
committerMark Andrews <marka@isc.org>
Sat, 8 Dec 2012 03:05:32 +0000 (14:05 +1100)
Squashed commit of the following:

commit 7ad3daade513c94a1c92ee7c91c112f161d13ef4
Author: Mark Andrews <marka@isc.org>
Date:   Mon Dec 3 15:03:44 2012 +1100

    look at the second token to determine if a TXT record in of unknown format or not

commit 7df32138462646f6aee84ffa56d02ac24ec8d672
Author: Mark Andrews <marka@isc.org>
Date:   Mon Dec 3 12:42:18 2012 +1100

    '"\#"' was incorrectly being treated as a unknown data escape sequence.

CHANGES
bin/tests/system/unknown/ns1/example-in.db
bin/tests/system/unknown/tests.sh
lib/dns/include/dns/rdata.h
lib/dns/rdata.c
lib/dns/rdata/generic/txt_16.c

diff --git a/CHANGES b/CHANGES
index 3a249bc05bc16a6147de53de23879e8c1d3fd5d8..5f8fd487fe070b62f8b5d14586463dc654b6d6da 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+3438.  [bug]           Don't accept unknown data escape in quotes. [RT #32031]
+
 3437.  [bug]           isc_buffer_init -> isc_buffer_constinit to initialise
                        buffers with constant data. [RT #32064]
 
index c8485d364c3c45326b4e8b5fe28a61b47dd2b0ac..63ea80deb8b56946eaa6a62b298a01f67a15d2d5 100644 (file)
@@ -53,6 +53,8 @@ txt4          CLASS1  TYPE16  "hello"
 txt5                   TXT     \# 6 0568656C6C6F
 txt6                   TYPE16  \# 6 0568656C6C6F
 txt7           IN      TXT     \# 6 0568656C6C6F
+txt8           IN      TXT     "\#" 2 0145
+txt9           IN      TXT     \# text
 
 unk1                   TYPE123 \# 1 00
 unk2           CLASS1  TYPE123 \# 1 00
index 14bb8539fdcd075d127bb0c56fc7d2fd50347b0b..f0f8e8fbcbb3f9492e4e85252c773c30a3b9bfce 100644 (file)
@@ -172,5 +172,19 @@ diff large.out dig.out > /dev/null || { ret=1 ; echo "I: diff failed"; }
 [ $ret = 0 ] || echo "I: failed"
 status=`expr $status + $ret`
 
+echo "I:check that '"'"\\#"'"' is not treated as the unknown escape sequence"
+ret=0
+DIG $DIGOPTS @10.53.0.1 +tcp +short txt8.example txt > dig.out
+echo '"#" "2" "0145"' | diff - dig.out || ret=1
+[ $ret = 0 ] || echo "I: failed"
+status=`expr $status + $ret`
+
+echo "I:check that '"'TXT \# text'"' is not treated as the unknown escape sequence"
+ret=0
+DIG $DIGOPTS @10.53.0.1 +tcp +short txt9.example txt > dig.out
+echo '"#" "text"' | diff - dig.out || ret=1
+[ $ret = 0 ] || echo "I: failed"
+status=`expr $status + $ret`
+
 echo "I:exit status: $status"
 exit $status
index 2c7b2730fb4c91a9ae407627feea9fabbbc91545..89ecaf8006966f3566e1e3cca1c35d2fb4763775 100644 (file)
@@ -177,6 +177,7 @@ struct dns_rdata {
 #define DNS_RDATA_CHECKREVERSE         DNS_NAME_CHECKREVERSE
 #define DNS_RDATA_CHECKMX              DNS_NAME_CHECKMX
 #define DNS_RDATA_CHECKMXFAIL          DNS_NAME_CHECKMXFAIL
+#define DNS_RDATA_UNKNOWNESCAPE                0x80000000
 
 /***
  *** Initialization
index 6e7c8a229e833b7423dbf232c807626c2c2d6d50..ed32d655383d2f5afbd11c37e122bb08fdc51fa2 100644 (file)
@@ -621,6 +621,7 @@ dns_rdata_fromtext(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
        void (*callback)(dns_rdatacallbacks_t *, const char *, ...);
        isc_result_t tresult;
        size_t length;
+       isc_boolean_t unknown;
 
        REQUIRE(origin == NULL || dns_name_isabsolute(origin) == ISC_TRUE);
        if (rdata != NULL) {
@@ -648,13 +649,33 @@ dns_rdata_fromtext(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
                return (result);
        }
 
-       if (strcmp(DNS_AS_STR(token), "\\#") == 0)
-               result = unknown_fromtext(rdclass, type, lexer, mctx, target);
-       else {
+       unknown = ISC_FALSE;
+       if (token.type == isc_tokentype_string &&
+           strcmp(DNS_AS_STR(token), "\\#") == 0) {
+               /*
+                * If this is a TXT record '\#' could be a escaped '#'.
+                * Look to see if the next token is a number and if so
+                * treat it as a unknown record format.
+                */
+               if (type == dns_rdatatype_txt) {
+                       result = isc_lex_getmastertoken(lexer, &token,
+                                                       isc_tokentype_number,
+                                                       ISC_FALSE);
+                       if (result == ISC_R_SUCCESS)
+                               isc_lex_ungettoken(lexer, &token);
+               }
+
+               if (result == ISC_R_SUCCESS) {
+                       unknown = ISC_TRUE;
+                       result = unknown_fromtext(rdclass, type, lexer,
+                                                 mctx, target);
+               } else
+                       options |= DNS_RDATA_UNKNOWNESCAPE;
+       } else 
                isc_lex_ungettoken(lexer, &token);
 
+       if (!unknown)
                FROMTEXTSWITCH
-       }
 
        /*
         * Consume to end of line / file.
index c49864e670a8cb74b33dc44345c5d35ec896d84d..be889808a0c9328cad465654c4214daa89c3dd78 100644 (file)
@@ -38,6 +38,13 @@ fromtext_txt(ARGS_FROMTEXT) {
        UNUSED(callbacks);
 
        strings = 0;
+       if ((options & DNS_RDATA_UNKNOWNESCAPE) != 0) {
+               isc_textregion_t r;
+               DE_CONST("#", r.base);
+               r.length = 1;
+               RETTOK(txt_fromtext(&r, target));
+               strings++;
+       }
        for (;;) {
                RETERR(isc_lex_getmastertoken(lexer, &token,
                                              isc_tokentype_qstring,