|
@@ -507,26 +507,33 @@ Name::toText(bool omit_final_dot) const {
|
|
|
|
|
|
NameComparisonResult
|
|
|
Name::compare(const Name& other) const {
|
|
|
- return (partial_compare(other, 0, 0));
|
|
|
+ return (partial_compare(other, 0, 0, labelcount_, other.labelcount_));
|
|
|
}
|
|
|
|
|
|
NameComparisonResult
|
|
|
Name::partial_compare(const Name& other,
|
|
|
unsigned int first_label,
|
|
|
unsigned int first_label_other,
|
|
|
+ unsigned int last_label,
|
|
|
+ unsigned int last_label_other,
|
|
|
bool case_sensitive) const {
|
|
|
// Determine the relative ordering under the DNSSEC order relation of
|
|
|
// 'this' and 'other', and also determine the hierarchical relationship
|
|
|
// of the names.
|
|
|
|
|
|
+ if ((first_label > last_label) ||
|
|
|
+ (first_label_other > last_label_other)) {
|
|
|
+ isc_throw(BadValue, "Bad label index ranges were passed");
|
|
|
+ }
|
|
|
+
|
|
|
if ((first_label > labelcount_) ||
|
|
|
(first_label_other > other.labelcount_)) {
|
|
|
isc_throw(BadValue, "Bad first label indices were passed");
|
|
|
}
|
|
|
|
|
|
unsigned int nlabels = 0;
|
|
|
- int l1 = labelcount_ - first_label;
|
|
|
- int l2 = other.labelcount_ - first_label_other;
|
|
|
+ int l1 = last_label - first_label;
|
|
|
+ int l2 = last_label_other - first_label_other;
|
|
|
int ldiff = (int)l1 - (int)l2;
|
|
|
unsigned int l = (ldiff < 0) ? l1 : l2;
|
|
|
|
|
@@ -558,16 +565,30 @@ Name::partial_compare(const Name& other,
|
|
|
}
|
|
|
|
|
|
if (chdiff != 0) {
|
|
|
- return (NameComparisonResult(chdiff, nlabels,
|
|
|
- NameComparisonResult::COMMONANCESTOR));
|
|
|
+ if ((nlabels == 0) &&
|
|
|
+ ((last_label < labelcount_) ||
|
|
|
+ (last_label_other < other.labelcount_))) {
|
|
|
+ return (NameComparisonResult(chdiff, 0,
|
|
|
+ NameComparisonResult::NONE));
|
|
|
+ } else {
|
|
|
+ return (NameComparisonResult(chdiff, nlabels,
|
|
|
+ NameComparisonResult::COMMONANCESTOR));
|
|
|
+ }
|
|
|
}
|
|
|
--count;
|
|
|
++pos1;
|
|
|
++pos2;
|
|
|
}
|
|
|
if (cdiff != 0) {
|
|
|
+ if ((nlabels == 0) &&
|
|
|
+ ((last_label < labelcount_) ||
|
|
|
+ (last_label_other < other.labelcount_))) {
|
|
|
+ return (NameComparisonResult(cdiff, 0,
|
|
|
+ NameComparisonResult::NONE));
|
|
|
+ } else {
|
|
|
return (NameComparisonResult(cdiff, nlabels,
|
|
|
- NameComparisonResult::COMMONANCESTOR));
|
|
|
+ NameComparisonResult::COMMONANCESTOR));
|
|
|
+ }
|
|
|
}
|
|
|
++nlabels;
|
|
|
}
|