MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ni6_dnsmatch

Function ni6_dnsmatch

freebsd/netinet6/icmp6.c:1592–1647  ·  view source on GitHub ↗

* check if two DNS-encoded string matches. takes care of truncated * form (with \0\0 at the end). no compression support. * XXX upper/lowercase match (see RFC2065) */

Source from the content-addressed store, hash-verified

1590 * XXX upper/lowercase match (see RFC2065)
1591 */
1592static int
1593ni6_dnsmatch(const char *a, int alen, const char *b, int blen)
1594{
1595 const char *a0, *b0;
1596 int l;
1597
1598 /* simplest case - need validation? */
1599 if (alen == blen && bcmp(a, b, alen) == 0)
1600 return 1;
1601
1602 a0 = a;
1603 b0 = b;
1604
1605 /* termination is mandatory */
1606 if (alen < 2 || blen < 2)
1607 return 0;
1608 if (a0[alen - 1] != '\0' || b0[blen - 1] != '\0')
1609 return 0;
1610 alen--;
1611 blen--;
1612
1613 while (a - a0 < alen && b - b0 < blen) {
1614 if (a - a0 + 1 > alen || b - b0 + 1 > blen)
1615 return 0;
1616
1617 if ((signed char)a[0] < 0 || (signed char)b[0] < 0)
1618 return 0;
1619 /* we don't support compression yet */
1620 if (a[0] >= 64 || b[0] >= 64)
1621 return 0;
1622
1623 /* truncated case */
1624 if (a[0] == 0 && a - a0 == alen - 1)
1625 return 1;
1626 if (b[0] == 0 && b - b0 == blen - 1)
1627 return 1;
1628 if (a[0] == 0 || b[0] == 0)
1629 return 0;
1630
1631 if (a[0] != b[0])
1632 return 0;
1633 l = a[0];
1634 if (a - a0 + 1 + l > alen || b - b0 + 1 + l > blen)
1635 return 0;
1636 if (bcmp(a + 1, b + 1, l) != 0)
1637 return 0;
1638
1639 a += 1 + l;
1640 b += 1 + l;
1641 }
1642
1643 if (a - a0 == alen && b - b0 == blen)
1644 return 1;
1645 else
1646 return 0;
1647}
1648
1649/*

Callers 1

ni6_inputFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected