From: Wouter Wijngaards Date: Mon, 13 Aug 2007 11:53:24 +0000 (+0000) Subject: hinfo treatment. X-Git-Tag: release-0.5~131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0374d468c8fa4cf412c439ff71b8db13255da67f;p=thirdparty%2Funbound.git hinfo treatment. git-svn-id: file:///svn/unbound/trunk@510 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index ca477f7d6..b4448653d 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -2,6 +2,7 @@ - fixup makefile, if lexer is missing give nice error and do not mess up the dependencies. - canonical compare routine updated. + - canonical hinfo compare. 10 August 2007: Wouter - malloc and free overrides that track total allocation and frees. diff --git a/validator/val_sigcrypt.c b/validator/val_sigcrypt.c index 01d6bf914..9de8ed358 100644 --- a/validator/val_sigcrypt.c +++ b/validator/val_sigcrypt.c @@ -446,6 +446,55 @@ struct canon_rr { size_t rr_idx; }; +/** + * Compare HINFO rrsets. For them, the string length bytes are not lowercased, + * but the string contents are lowercased. + * + * This routine works for any 'all STR' RR type. It works similar to the + * compare_byfield routine, but stripped down, and modified to lowercase + * STR fields. + * + * @param d: rrset data + * @param i: first RR to compare + * @param j: first RR to compare + * @return comparison code. + */ +static int +canonical_compare_hinfo(struct packed_rrset_data* d, size_t i, size_t j) +{ + uint8_t* di = d->rr_data[i]+2; /* ptr to current rdata byte */ + uint8_t* dj = d->rr_data[j]+2; + size_t ilen = d->rr_len[i]-2; /* length left in rdata */ + size_t jlen = d->rr_len[j]-2; + size_t strlen_i = 0; + size_t strlen_j = 0; + while(ilen > 0 && jlen > 0) { + /* compare this pair of bytes */ + if( ((strlen_i)?(uint8_t)tolower((int)*di++):*di++) + != ((strlen_j)?(uint8_t)tolower((int)*dj++):*dj++) + ) { + if(((strlen_i)?(uint8_t)tolower((int)*di++):*di++) + < ((strlen_j)?(uint8_t)tolower((int)*dj++):*dj++)) + return -1; + return 1; + } + ilen --; + jlen --; + /* read length byte of the string in rdata if strlen=0 */ + if(strlen_i == 0) { + strlen_i = (size_t)di[-1]; + } else strlen_i--; + if(strlen_j == 0) { + strlen_j = (size_t)dj[-1]; + } else strlen_j--; + } + if(ilen == 0 && jlen == 0) + return 0; + if(ilen == 0) + return -1; + return 1; +} + /** * Compare two RR for canonical order, in a field-style sweep. * @param d: rrset data @@ -650,6 +699,7 @@ canonical_compare(struct ub_packed_rrset_key* rrset, size_t i, size_t j) /* This RR type is special, as the contents of text fields * is lowercased. */ case LDNS_RR_TYPE_HINFO: + return canonical_compare_hinfo(d, i, j); default: /* For unknown RR types, or types not listed above,