]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix parse in sldns of quoted parenthesized text strings.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 3 Feb 2014 14:28:57 +0000 (14:28 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 3 Feb 2014 14:28:57 +0000 (14:28 +0000)
git-svn-id: file:///svn/unbound/trunk@3066 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
ldns/str2wire.c
testdata/test_ldnsrr.5
testdata/test_ldnsrr.c5

index e00c80623050a2623c041b9c9df0e0241ede1e5b..1243ac0493d9100097b490f1bb8eb4f1c356d84e 100644 (file)
@@ -1,6 +1,7 @@
 3 February 2014: Wouter
        - Detect libevent2 install automatically by configure.
        - Fixup link with lib/event2 subdir.
+       - Fix parse in sldns of quoted parenthesized text strings.
 
 31 January 2014: Wouter
        - unit test for ldns wire to str and back with zones, root, nlnetlabs
index e88bbf7dac961ce4574906a458b080a4fc64037c..5a09a132617a28ffa8f513a38cd43c6c5847c2b9 100644 (file)
@@ -534,7 +534,7 @@ rrinternal_parse_rdata(sldns_buffer* strbuf, char* token, size_t token_len,
        const sldns_rr_descriptor *desc = sldns_rr_descript((uint16_t)rr_type);
        uint16_t r_cnt, r_min, r_max;
        size_t rr_cur_len = dname_len + 10, pre_data_pos, token_strlen;
-       int was_unknown_rr_format = 0, parens = 0, status, quoted;
+       int was_unknown_rr_format = 0, parens = 0, status, quoted, tokquote;
        const char* delimiters;
        sldns_rdf_type rdftype;
        /* a desc is always returned */
@@ -560,14 +560,49 @@ rrinternal_parse_rdata(sldns_buffer* strbuf, char* token, size_t token_len,
                }
 
                pre_data_pos = sldns_buffer_position(strbuf);
-               if(sldns_bget_token_par(strbuf, token, delimiters, token_len,
-                       &parens, quoted?NULL:" \t") == -1) {
+               if(sldns_bget_token_par(strbuf, token, quoted?"\"":delimiters,
+                       token_len, &parens, quoted?NULL:" \t") == -1) {
                        break;
                }
-               /* hmmz, rfc3597 specifies that any type can be represented
+               token_strlen = strlen(token);
+               /* check if not quoted yet, and we have encountered quotes */
+               if(!quoted && sldns_rdf_type_maybe_quoted(rdftype) &&
+                       token_strlen >= 2 &&
+                       (token[0] == '"' || token[0] == '\'') && 
+                       (token[token_strlen-1] == '"' || token[token_strlen-1] == '\'')) {
+                       /* move token two smaller (quotes) with endnull */
+                       memmove(token, token+1, token_strlen-2);
+                       token[token_strlen-2] = 0;
+                       token_strlen -= 2;
+                       quoted = 1;
+                       tokquote = 1; /* do not read endquotechar from buffer */
+               } else if(!quoted && sldns_rdf_type_maybe_quoted(rdftype) &&
+                       token_strlen >= 2 &&
+                       (token[0] == '"' || token[0] == '\'')) {
+                       /* got the start quote (remove it) but read remainder
+                        * of quoted string as well into remainder of token */
+                       memmove(token, token+1, token_strlen-1);
+                       token[token_strlen-1] = 0;
+                       token_strlen -= 1;
+                       quoted = 1;
+                       tokquote = 0;
+                       /* rewind buffer over skipped whitespace */
+                       while(sldns_buffer_position(strbuf) > 0 &&
+                               (sldns_buffer_current(strbuf)[-1] == ' ' ||
+                               sldns_buffer_current(strbuf)[-1] == '\t')) {
+                               sldns_buffer_skip(strbuf, -1);
+                       }
+                       if(sldns_bget_token_par(strbuf, token+token_strlen,
+                               "\"", token_len-token_strlen,
+                               &parens, NULL) == -1) {
+                               break;
+                       }
+                       token_strlen = strlen(token);
+               } else tokquote = 0;
+
+               /* rfc3597 specifies that any type can be represented
                 * with \# method, which can contain spaces...
                 * it does specify size though... */
-               token_strlen = strlen(token);
 
                /* unknown RR data */
                if(token_strlen>=2 && strncmp(token, "\\#", 2) == 0 &&
@@ -577,7 +612,7 @@ rrinternal_parse_rdata(sldns_buffer* strbuf, char* token, size_t token_len,
                                token_len, rr, rr_len, &rr_cur_len, 
                                pre_data_pos)) != 0)
                                return status;
-               } else {
+               } else if(token_strlen > 0 || quoted) {
                        /* normal RR */
                        if((status=rrinternal_parse_rdf(strbuf, token,
                                token_len, rr, *rr_len, &rr_cur_len, rdftype,
@@ -586,7 +621,7 @@ rrinternal_parse_rdata(sldns_buffer* strbuf, char* token, size_t token_len,
                                return status;
                        }
                }
-               if(quoted) {
+               if(quoted && !tokquote) {
                        if(sldns_buffer_available(strbuf, 1))
                                sldns_buffer_skip(strbuf, 1);
                        else    break;
index 862eee73ef29f44c2684d32c996e317f9d81026f..c99d2a65f0f117185e9ce9446d087ba1d1481900 100644 (file)
@@ -113,3 +113,9 @@ eui64               IN EUI64 00-00-5e-ef-00-00-00-2a
 ;error.eui64   IN EUI64 00-00-5e-ef-00-00-00-2a-ef ; too long
 ;error.eui64   IN EUI64 00-00-5e-ef-r0-00-00-2a ; non-hex
 
+; Tests for Unbound
+; the text strings should be identical, with () and without (), parse test.
+txt1   TXT     "a" "bb" "ccc"
+txt2   TXT     ( "a" "bb" "ccc" )
+txt3   TXT     "a b" "bb" " cc c " " "
+txt4   TXT     ( "a b" "bb" " cc c " " " )
index 3ca2e81c47cf9ab74c5c8147e499f29268ebef63..45414eaa33826be7a0d6b38fe9acf52a6d9761f4 100644 (file)
@@ -128,3 +128,11 @@ caa.       3600    IN      CAA     \# 70 020461757468303E3039060A2B06010401D6790203010609608648016
 eui48. 3600    IN      EUI48   00-00-5e-90-01-2a
 05657569363400006D000100000E10000800005EEF0000002A
 eui64. 3600    IN      EUI64   00-00-5e-ef-00-00-00-2a
+0474787431000010000100000E100009016102626203636363
+txt1.  3600    IN      TXT     "a" "bb" "ccc"
+0474787432000010000100000E100009016102626203636363
+txt2.  3600    IN      TXT     "a" "bb" "ccc"
+0474787433000010000100000E10001003612062026262062063632063200120
+txt3.  3600    IN      TXT     "a b" "bb" " cc c " " "
+0474787434000010000100000E10001003612062026262062063632063200120
+txt4.  3600    IN      TXT     "a b" "bb" " cc c " " "