* If one or the other isn't a letter, we can't
* do case insensitive comparisons of them, so
* they can't match.
- *
- * @todo - allow for '_' at the beginning of a
- * label.
*/
if (!(((*a >= 'a') && (*a <= 'z')) || ((*a >= 'A') && (*a <= 'Z')))) return false;
if (!(((*b >= 'a') && (*b <= 'z')) || ((*b >= 'A') && (*b <= 'Z')))) return false;
uint8_t const *end = buf + buf_len;
uint8_t const *q, *strend, *last;
uint8_t *data;
+ bool underscore = true;
if (!buf || !buf_len || !where || !value) {
fr_strerror_const("Invalid input");
}
/*
- * @todo - allow for '_' at the beginning of a
- * label.
+ * Convert it piece by piece.
*/
while (q < strend) {
+ /*
+ * Allow underscore at the start of a label.
+ */
+ if (underscore) {
+ underscore = false;
+
+ if (*q == '_') goto next;
+ }
+
if (*q == '.') {
/*
* Don't count final dot as an
}
last = q;
+ /*
+ * We had a dot, allow underscore as the
+ * first character of the next label.
+ */
+ underscore = true;
+
} else if (!((*q == '-') || ((*q >= '0') && (*q <= '9')) ||
((*q >= 'A') && (*q <= 'Z')) || ((*q >= 'a') && (*q <= 'z')))) {
- fr_strerror_printf("Invalid character %02x in label", *q);
+ fr_strerror_printf("Invalid character 0x%02x in label", *q);
return -1;
}
+ next:
q++;
if ((q - last) > 63) {
*/
ssize_t fr_dns_label_uncompressed_length(uint8_t const *buf, size_t buf_len, uint8_t const **next)
{
- uint8_t const *p, *q, *end;
+ uint8_t const *p, *q, *end, *label_end;
uint8_t const *current, *start;
size_t length;
bool at_first_label, already_set_next;
return -(p - buf);
}
+ q = p + 1;
+ label_end = q + *p;
+
+ /*
+ * Allow for underscore at the beginning of a
+ * label.
+ */
+ if (*q == '_') q++;
+
/*
* Verify that the contents of the label are OK.
*/
- for (q = p + 1; q < p + *p + 1; q++) {
- /*
- * @todo - allow for '_' at the beginning of a
- * label.
- */
+ while (q < label_end) {
if (!((*q == '-') || ((*q >= '0') && (*q <= '9')) ||
((*q >= 'A') && (*q <= 'Z')) || ((*q >= 'a') && (*q <= 'z')))) {
- fr_strerror_printf("Invalid character %02x in label", *q);
+ fr_strerror_printf("Invalid character 0x%02x in label", *q);
return -(q - buf);
}
+
+ q++;
}
p += *p + 1;
decode-dns-label -
match www.example.com,ftp.example.com,www.example.org,ftp.example.org,ns.example.org
+#
+# Underscores are allowed as the first character of a label.
+#
+encode-dns-label _foo.com
+match 04 5f 66 6f 6f 03 63 6f 6d 00
+
+decode-dns-label -
+match _foo.com
+
#
# Error cases
#
encode-dns-label www..foo.com
match Double dots '..' are forbidden
+# underscore as non-first character is illegal
+encode-dns-label www_foo.com
+match Invalid character 0x5f in label
count
-match 98
+match 104