From: Felipe Gasper Date: Wed, 16 Mar 2022 00:57:00 +0000 (-0400) Subject: Ensure uniform handling of spaces & tabs when parsing RRs. X-Git-Tag: 1.8.2-rc.1~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F159%2Fhead;p=thirdparty%2Fldns.git Ensure uniform handling of spaces & tabs when parsing RRs. Issue #157: This fixes the same type of bug as #147, in a couple places where that issue’s fix didn’t apply. A small refactor is done to deduplicate whitespace-checking logic. Tests are added as well. --- diff --git a/rr.c b/rr.c index 382d0b59..2f64c15d 100644 --- a/rr.c +++ b/rr.c @@ -20,6 +20,12 @@ #define LDNS_TTL_DATALEN 21 #define LDNS_RRLIST_INIT 8 +#define _IS_WHITESPACE(chr) \ + ( NULL != strchr( LDNS_PARSE_NO_NL, chr) ) + +#define _BUFFER_IS_AT_WHITESPACE(rd_buf) \ + _IS_WHITESPACE(*(ldns_buffer_current(rd_buf))) + ldns_rr * ldns_rr_new(void) { @@ -372,9 +378,9 @@ ldns_rr_new_frm_str_internal(ldns_rr **newrr, const char *str, desc, r_cnt)) && ldns_buffer_remaining(rd_buf) > 0){ - /* skip spaces & tabs */ + /* skip whitespace */ while (ldns_buffer_remaining(rd_buf) > 0 && - NULL != strchr( LDNS_PARSE_NO_NL, *(ldns_buffer_current(rd_buf)) )) { + _BUFFER_IS_AT_WHITESPACE(rd_buf)) { ldns_buffer_skip(rd_buf, 1); } @@ -396,9 +402,9 @@ ldns_rr_new_frm_str_internal(ldns_rr **newrr, const char *str, * _maximum() only */ - /* skip spaces */ + /* skip whitespace */ while (ldns_buffer_position(rd_buf) < ldns_buffer_limit(rd_buf) - && *(ldns_buffer_current(rd_buf)) == ' ' + && _BUFFER_IS_AT_WHITESPACE(rd_buf) && !quoted) { ldns_buffer_skip(rd_buf, 1); @@ -420,7 +426,7 @@ ldns_rr_new_frm_str_internal(ldns_rr **newrr, const char *str, /* unknown RR data */ if (strncmp(rd, "\\#", 2) == 0 && !quoted && - (rd_strlen == 2 || rd[2]==' ')) { + (rd_strlen == 2 || _IS_WHITESPACE(rd[2]))) { was_unknown_rr_format = 1; /* go back to before \# diff --git a/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.db b/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.db new file mode 100644 index 00000000..99730d31 --- /dev/null +++ b/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.db @@ -0,0 +1 @@ +com. 14400 IN NAPTR 100 10 S SIP+D2U "!^.*$!sip:customer-service@example.com!" com. diff --git a/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.dsc b/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.dsc new file mode 100644 index 00000000..9017a0e6 --- /dev/null +++ b/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.dsc @@ -0,0 +1,16 @@ +BaseName: 28-tab-instead-of-space +Version: 1.0 +Description: Check for GH 157 regression +CreationDate: Tue Mar 15 21:01:34 EST 2022 +Maintainer: +Category: +Component: +CmdDepends: +Depends: +Help: 28-tab-instead-of-space.help +Pre: +Post: +Test: 28-tab-instead-of-space.test +AuxFiles: +Passed: +Failure: diff --git a/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.help b/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.help new file mode 100644 index 00000000..f54a7906 --- /dev/null +++ b/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.help @@ -0,0 +1 @@ +This requires no arguments. diff --git a/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.test b/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.test new file mode 100644 index 00000000..3c6ab2cd --- /dev/null +++ b/test/28-tab-instead-of-space.tpkg/28-tab-between-cstrings-2.test @@ -0,0 +1,15 @@ +# #-- 28-tab-instead-of-space.test --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master + +export PATH=$PATH:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:. + +export LD_LIBRARY_PATH=../../lib:$LD_LIBRARY_PATH + +OUTPUT=`../../examples/ldns-read-zone 28-tab-instead-of-space.db` + +if [[ $? -eq 0 ]]; then + echo $OUTPUT | grep customer-service +else + exit 1 +fi diff --git a/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.db b/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.db new file mode 100644 index 00000000..d32d21d4 --- /dev/null +++ b/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.db @@ -0,0 +1,2 @@ +a.example. CLASS32 TYPE731 \# 6 abcd ( + ef 01 23 45 ) diff --git a/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.dsc b/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.dsc new file mode 100644 index 00000000..67927e1f --- /dev/null +++ b/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.dsc @@ -0,0 +1,16 @@ +BaseName: 29-generic-rdata-tab +Version: 1.0 +Description: Check for GH 157 regression +CreationDate: Tue Mar 15 21:01:34 EST 2022 +Maintainer: +Category: +Component: +CmdDepends: +Depends: +Help: 29-generic-rdata-tab.help +Pre: +Post: +Test: 29-generic-rdata-tab.test +AuxFiles: +Passed: +Failure: diff --git a/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.help b/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.help new file mode 100644 index 00000000..f54a7906 --- /dev/null +++ b/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.help @@ -0,0 +1 @@ +This requires no arguments. diff --git a/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.test b/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.test new file mode 100644 index 00000000..e38136dd --- /dev/null +++ b/test/29-generic-rdata-tab.tpkg/29-generic-rdata-tab.test @@ -0,0 +1,15 @@ +# #-- 29-generic-rdata-tab.test --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master + +export PATH=$PATH:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:. + +export LD_LIBRARY_PATH=../../lib:$LD_LIBRARY_PATH + +OUTPUT=`../../examples/ldns-read-zone 29-generic-rdata-tab.db` + +if [[ $? -eq 0 ]]; then + echo $OUTPUT | grep CLASS32 +else + exit 1 +fi