From 8af5175d702f5d198d731adf760edf3bdcb60817 Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 2 Mar 2000 00:58:07 +0000 Subject: [PATCH] + * In answers, quote everything except alphanums and - _ / + and document @@ -4,6 +4,8 @@ + * In answers, quote everything except alphanums and - _ / + and document + this behaviour. Make not setting adns_qf_quotefail_cname work. --- changelog | 2 + regress/case-quote.err | 0 regress/case-quote.out | 28 ++++++ regress/case-quote.sys | 211 +++++++++++++++++++++++++++++++++++++++++ src/adns.h | 20 ++-- src/internal.h | 3 + src/parse.c | 9 +- src/reply.c | 2 +- 8 files changed, 263 insertions(+), 12 deletions(-) create mode 100644 regress/case-quote.err create mode 100644 regress/case-quote.out create mode 100644 regress/case-quote.sys diff --git a/changelog b/changelog index 155d177..3989b51 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,8 @@ adns (0.7) BETA; urgency=medium * Better reporting of unexpected or weird replies from nameserver. * Better checking of long domain names and labels in queries. * Unfortunately, answer->owner may be null on error. Documented. + * In answers, quote everything except alphanums and - _ / + and document + this behaviour. Make not setting adns_qf_quotefail_cname work. -- diff --git a/regress/case-quote.err b/regress/case-quote.err new file mode 100644 index 0000000..e69de29 diff --git a/regress/case-quote.out b/regress/case-quote.out new file mode 100644 index 0000000..a72dcd9 --- /dev/null +++ b/regress/case-quote.out @@ -0,0 +1,28 @@ +adns debug: using nameserver 172.18.45.6 +hyphen.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +dot.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +plus.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +slash.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +underscore.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +quote.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +backslash.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +null.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +space.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +hash.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +del.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +meta-null.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +meta-del.cname.test.iwj.relativity.greenend.org.uk flags 0 type 1 A(-) submitted +hyphen.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a-b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +dot.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a\.b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +plus.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a+b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +slash.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a/b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +underscore.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a_b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +quote.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a\"b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +backslash.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a\\b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +null.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a\000b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +space.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a\040b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +hash.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a\#b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +del.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a\177b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +meta-null.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a\310b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +meta-del.cname.test.iwj.relativity.greenend.org.uk flags 0 type A(-): No such domain; nrrs=0; cname=a\377b.cname.test.iwj.relativity.greenend.org.uk; owner=$; ttl=60 +rc=0 diff --git a/regress/case-quote.sys b/regress/case-quote.sys new file mode 100644 index 0000000..75e44d4 --- /dev/null +++ b/regress/case-quote.sys @@ -0,0 +1,211 @@ +default +:1 hyphen.cname.test.iwj.relativity.greenend.org.uk dot.cname.test.iwj.relativity.greenend.org.uk plus.cname.test.iwj.relativity.greenend.org.uk slash.cname.test.iwj.relativity.greenend.org.uk underscore.cname.test.iwj.relativity.greenend.org.uk quote.cname.test.iwj.relativity.greenend.org.uk backslash.cname.test.iwj.relativity.greenend.org.uk null.cname.test.iwj.relativity.greenend.org.uk space.cname.test.iwj.relativity.greenend.org.uk hash.cname.test.iwj.relativity.greenend.org.uk del.cname.test.iwj.relativity.greenend.org.uk meta-null.cname.test.iwj.relativity.greenend.org.uk meta-del.cname.test.iwj.relativity.greenend.org.uk + start 951958420.936685 + socket type=SOCK_DGRAM + socket=4 + +0.000229 + fcntl fd=4 cmd=F_GETFL + fcntl=~O_NONBLOCK&... + +0.000057 + fcntl fd=4 cmd=F_SETFL O_NONBLOCK|... + fcntl=OK + +0.000034 + sendto fd=4 addr=172.18.45.6:53 + 311f0100 00010000 00000000 06687970 68656e05 636e616d 65047465 73740369 + 776a0a72 656c6174 69766974 79086772 65656e65 6e64036f 72670275 6b000001 + 0001. + sendto=66 + +0.001345 + sendto fd=4 addr=172.18.45.6:53 + 31200100 00010000 00000000 03646f74 05636e61 6d650474 65737403 69776a0a + 72656c61 74697669 74790867 7265656e 656e6403 6f726702 756b0000 010001. + sendto=63 + +0.000708 + sendto fd=4 addr=172.18.45.6:53 + 31210100 00010000 00000000 04706c75 7305636e 616d6504 74657374 0369776a + 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 00010001. + sendto=64 + +0.000669 + sendto fd=4 addr=172.18.45.6:53 + 31220100 00010000 00000000 05736c61 73680563 6e616d65 04746573 74036977 + 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b 00000100 + 01. + sendto=65 + +0.000670 + sendto fd=4 addr=172.18.45.6:53 + 31230100 00010000 00000000 0a756e64 65727363 6f726505 636e616d 65047465 + 73740369 776a0a72 656c6174 69766974 79086772 65656e65 6e64036f 72670275 + 6b000001 0001. + sendto=70 + +0.000690 + sendto fd=4 addr=172.18.45.6:53 + 31240100 00010000 00000000 0571756f 74650563 6e616d65 04746573 74036977 + 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b 00000100 + 01. + sendto=65 + +0.000699 + sendto fd=4 addr=172.18.45.6:53 + 31250100 00010000 00000000 09626163 6b736c61 73680563 6e616d65 04746573 + 74036977 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b + 00000100 01. + sendto=69 + +0.000911 + sendto fd=4 addr=172.18.45.6:53 + 31260100 00010000 00000000 046e756c 6c05636e 616d6504 74657374 0369776a + 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 00010001. + sendto=64 + +0.000831 + sendto fd=4 addr=172.18.45.6:53 + 31270100 00010000 00000000 05737061 63650563 6e616d65 04746573 74036977 + 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b 00000100 + 01. + sendto=65 + +0.000684 + sendto fd=4 addr=172.18.45.6:53 + 31280100 00010000 00000000 04686173 6805636e 616d6504 74657374 0369776a + 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 00010001. + sendto=64 + +0.000672 + sendto fd=4 addr=172.18.45.6:53 + 31290100 00010000 00000000 0364656c 05636e61 6d650474 65737403 69776a0a + 72656c61 74697669 74790867 7265656e 656e6403 6f726702 756b0000 010001. + sendto=63 + +0.000715 + sendto fd=4 addr=172.18.45.6:53 + 312a0100 00010000 00000000 096d6574 612d6e75 6c6c0563 6e616d65 04746573 + 74036977 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b + 00000100 01. + sendto=69 + +0.000695 + sendto fd=4 addr=172.18.45.6:53 + 312b0100 00010000 00000000 086d6574 612d6465 6c05636e 616d6504 74657374 + 0369776a 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 + 00010001. + sendto=68 + +0.000695 + select max=5 rfds=[4] wfds=[] efds=[] to=1.990016 + select=1 rfds=[4] wfds=[] efds=[] + +0.000248 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 311f8583 00010001 00010000 06687970 68656e05 636e616d 65047465 73740369 + 776a0a72 656c6174 69766974 79086772 65656e65 6e64036f 72670275 6b000001 + 0001c00c 00050001 0000003c 002f0361 2d620563 6e616d65 04746573 74036977 + 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b 00c05800 + 06000100 00003c00 27036e73 30c0610a 686f7374 6d617374 6572c061 00000023 + 00000e10 00000078 0064c800 0000003c. + +0.000645 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 31208583 00010001 00010000 03646f74 05636e61 6d650474 65737403 69776a0a + 72656c61 74697669 74790867 7265656e 656e6403 6f726702 756b0000 010001c0 + 0c000500 01000000 3c002f03 612e6205 636e616d 65047465 73740369 776a0a72 + 656c6174 69766974 79086772 65656e65 6e64036f 72670275 6b00c055 00060001 + 0000003c 0027036e 7330c05e 0a686f73 746d6173 746572c0 5e000000 2300000e + 10000000 780064c8 00000000 3c. + +0.001014 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 31218583 00010001 00010000 04706c75 7305636e 616d6504 74657374 0369776a + 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 00010001 + c00c0005 00010000 003c002f 03612b62 05636e61 6d650474 65737403 69776a0a + 72656c61 74697669 74790867 7265656e 656e6403 6f726702 756b00c0 56000600 + 01000000 3c002703 6e7330c0 5f0a686f 73746d61 73746572 c05f0000 00230000 + 0e100000 00780064 c8000000 003c. + +0.000717 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 31228583 00010001 00010000 05736c61 73680563 6e616d65 04746573 74036977 + 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b 00000100 + 01c00c00 05000100 00003c00 2f03612f 6205636e 616d6504 74657374 0369776a + 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 c0570006 + 00010000 003c0027 036e7330 c0600a68 6f73746d 61737465 72c06000 00002300 + 000e1000 00007800 64c80000 00003c. + +0.000666 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 31238583 00010001 00010000 0a756e64 65727363 6f726505 636e616d 65047465 + 73740369 776a0a72 656c6174 69766974 79086772 65656e65 6e64036f 72670275 + 6b000001 0001c00c 00050001 0000003c 002f0361 5f620563 6e616d65 04746573 + 74036977 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b + 00c05c00 06000100 00003c00 27036e73 30c0650a 686f7374 6d617374 6572c065 + 00000023 00000e10 00000078 0064c800 0000003c. + +0.000663 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 31248583 00010001 00010000 0571756f 74650563 6e616d65 04746573 74036977 + 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b 00000100 + 01c00c00 05000100 00003c00 2f036122 6205636e 616d6504 74657374 0369776a + 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 c0570006 + 00010000 003c0027 036e7330 c0600a68 6f73746d 61737465 72c06000 00002300 + 000e1000 00007800 64c80000 00003c. + +0.000667 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 31258583 00010001 00010000 09626163 6b736c61 73680563 6e616d65 04746573 + 74036977 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b + 00000100 01c00c00 05000100 00003c00 2f03615c 6205636e 616d6504 74657374 + 0369776a 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 + c05b0006 00010000 003c0027 036e7330 c0640a68 6f73746d 61737465 72c06400 + 00002300 000e1000 00007800 64c80000 00003c. + +0.000663 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 31268583 00010001 00010000 046e756c 6c05636e 616d6504 74657374 0369776a + 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 00010001 + c00c0005 00010000 003c002f 03610062 05636e61 6d650474 65737403 69776a0a + 72656c61 74697669 74790867 7265656e 656e6403 6f726702 756b00c0 56000600 + 01000000 3c002703 6e7330c0 5f0a686f 73746d61 73746572 c05f0000 00230000 + 0e100000 00780064 c8000000 003c. + +0.000670 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 31278583 00010001 00010000 05737061 63650563 6e616d65 04746573 74036977 + 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b 00000100 + 01c00c00 05000100 00003c00 2f036120 6205636e 616d6504 74657374 0369776a + 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 c0570006 + 00010000 003c0027 036e7330 c0600a68 6f73746d 61737465 72c06000 00002300 + 000e1000 00007800 64c80000 00003c. + +0.000651 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 31288583 00010001 00010000 04686173 6805636e 616d6504 74657374 0369776a + 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 00010001 + c00c0005 00010000 003c002f 03612362 05636e61 6d650474 65737403 69776a0a + 72656c61 74697669 74790867 7265656e 656e6403 6f726702 756b00c0 56000600 + 01000000 3c002703 6e7330c0 5f0a686f 73746d61 73746572 c05f0000 00230000 + 0e100000 00780064 c8000000 003c. + +0.000664 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 31298583 00010001 00010000 0364656c 05636e61 6d650474 65737403 69776a0a + 72656c61 74697669 74790867 7265656e 656e6403 6f726702 756b0000 010001c0 + 0c000500 01000000 3c002f03 617f6205 636e616d 65047465 73740369 776a0a72 + 656c6174 69766974 79086772 65656e65 6e64036f 72670275 6b00c055 00060001 + 0000003c 0027036e 7330c05e 0a686f73 746d6173 746572c0 5e000000 2300000e + 10000000 780064c8 00000000 3c. + +0.000646 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 312a8583 00010001 00010000 096d6574 612d6e75 6c6c0563 6e616d65 04746573 + 74036977 6a0a7265 6c617469 76697479 08677265 656e656e 64036f72 6702756b + 00000100 01c00c00 05000100 00003c00 2f0361c8 6205636e 616d6504 74657374 + 0369776a 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 + c05b0006 00010000 003c0027 036e7330 c0640a68 6f73746d 61737465 72c06400 + 00002300 000e1000 00007800 64c80000 00003c. + +0.000708 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 312b8583 00010001 00010000 086d6574 612d6465 6c05636e 616d6504 74657374 + 0369776a 0a72656c 61746976 69747908 67726565 6e656e64 036f7267 02756b00 + 00010001 c00c0005 00010000 003c002f 0361ff62 05636e61 6d650474 65737403 + 69776a0a 72656c61 74697669 74790867 7265656e 656e6403 6f726702 756b00c0 + 5a000600 01000000 3c002703 6e7330c0 630a686f 73746d61 73746572 c0630000 + 00230000 0e100000 00780064 c8000000 003c. + +0.000665 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=EAGAIN + +0.000123 + close fd=4 + close=OK + +0.000708 diff --git a/src/adns.h b/src/adns.h index 6643864..a1e0877 100644 --- a/src/adns.h +++ b/src/adns.h @@ -90,7 +90,7 @@ typedef enum { adns_qf_search= 0x00000001, /* use the searchlist */ adns_qf_usevc= 0x00000002, /* use a virtual circuit (TCP connection) */ adns_qf_owner= 0x00000004, /* fill in the owner field in the answer */ - adns_qf_quoteok_query= 0x00000010, /* allow quote-requiring chars in query domain */ + adns_qf_quoteok_query= 0x00000010, /* allow special chars in query domain */ adns_qf_quoteok_cname= 0x00000000, /* allow ... in CNAME we go via - now default */ adns_qf_quoteok_anshost= 0x00000040, /* allow ... in things supposed to be hostnames */ adns_qf_quotefail_cname= 0x00000080, /* refuse if quote-req chars in CNAME we go via */ @@ -142,11 +142,19 @@ typedef enum { * In queries _with_ qf_quoteok_*, domains in the query or response * may contain any characters, quoted according to RFC1035 5.1. On * input to adns, the char* is a pointer to the interior of a " - * delimited string, except that " may appear in it, and on output, - * the char* is a pointer to a string which would be legal either - * inside or outside " delimiters, and any characters not usually - * legal in domain names will be quoted as \X (if the character is - * 33-126 except \ and ") or \DDD. + * delimited string, except that " may appear in it unquoted. On + * output, the char* is a pointer to a string which would be legal + * either inside or outside " delimiters; any character which isn't + * legal in a hostname (ie alphanumeric or hyphen) or one of _ / + + * (the three other punctuation characters commonly abused in domain + * names) will be quoted, as \X if it is a printing ASCII character or + * \DDD otherwise. + * + * (The characters which will be unquoted are the printing 7-bit ASCII + * characters except the punctuation characters " ( ) @ ; $ \ + + * I.e. unquoted characters are alphanumerics, and the following + * punctuation characters: ! # % ^ & * - _ = + [ ] { } * * If the query goes via a CNAME then the canonical name (ie, the * thing that the CNAME record refers to) is usually allowed to diff --git a/src/internal.h b/src/internal.h index 9e442fe..4fc7d7f 100644 --- a/src/internal.h +++ b/src/internal.h @@ -683,6 +683,9 @@ static inline int ctype_alpha(int c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } static inline int ctype_822special(int c) { return strchr("()<>@,;:\\\".[]",c) != 0; } +static inline int ctype_domainunquoted(int c) { + return ctype_alpha(c) || ctype_digit(c) || (strchr("-_/+",c) != 0); +} static inline int errno_resources(int e) { return e==ENOMEM || e==ENOBUFS; } diff --git a/src/parse.c b/src/parse.c index 9a4e0c7..59fe7b5 100644 --- a/src/parse.c +++ b/src/parse.c @@ -35,13 +35,12 @@ int vbuf__append_quoted1035(vbuf *vb, const byte *buf, int len) { qbuf[0]= 0; for (i=0; i= 127) { + if (ch <= ' ' || ch >= 127) { sprintf(qbuf,"\\%03o",ch); break; + } else if (!ctype_domainunquoted(ch)) { + sprintf(qbuf,"\\%c",ch); + break; } } if (!adns__vbuf_append(vb,buf,i) || !adns__vbuf_append(vb,qbuf,strlen(qbuf))) diff --git a/src/reply.c b/src/reply.c index 905d037..586aff0 100644 --- a/src/reply.c +++ b/src/reply.c @@ -198,7 +198,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, qu->cname_begin= rdstart; qu->cname_dglen= dglen; st= adns__parse_domain(ads,serv,qu, &qu->vb, - qu->flags & adns_qf_quoteok_cname ? pdf_quoteok : 0, + qu->flags & adns_qf_quotefail_cname ? 0 : pdf_quoteok, dgram,dglen, &rdstart,rdstart+rdlength); if (!qu->vb.used) goto x_truncated; if (st) { adns__query_fail(qu,st); return; } -- 2.30.2