BugID:17160501:Fix for dns name case sensitive issue
@@ -171,6 +171,10 @@ static u16_t dns_txid;
#define LWIP_DNS_SET_ADDRTYPE(x, y)
#endif /* LWIP_IPV4 && LWIP_IPV6 */
+#define lwip_in_range(c, lo, up) ((u8_t)(c) >= (lo) && (u8_t)(c) <= (up))
+#define lwip_isupper(c) lwip_in_range((c), 'A', 'Z')
+#define lwip_tolower(c) (lwip_isupper(c) ? (c) - 'A' + 'a' : c)
+
/** DNS query message structure.
No packing needed: only used locally on the stack. */
struct dns_query {
@@ -586,10 +590,12 @@ dns_compare_name(const char *query, struct pbuf *p, u16_t start_offset)
u16_t response_offset = start_offset;
do {
- n = pbuf_try_get_at(p, response_offset++);
- if (n < 0) {
+ n = pbuf_try_get_at(p, response_offset);
+ if (n < 0 || response_offset == 0xFFFF) {
+ /* error or overflow */
return 0xFFFF;
}
+ response_offset++;
/** @see RFC 1035 - 4.1.4. Message compression */
if ((n & 0xc0) == 0xc0) {
/* Compressed name: cannot be equal since we don't send them */
@@ -601,7 +607,11 @@ dns_compare_name(const char *query, struct pbuf *p, u16_t start_offset)
if (c < 0) {
return 0xFFFF;
}
- if ((*query) != (u8_t)c) {
+ if (lwip_tolower((*query)) != lwip_tolower((u8_t)c)) {
+ return 0xFFFF;
+ }
+ if (response_offset == 0xFFFF) {
+ /* would overflow */
return 0xFFFF;
}
++response_offset;
@@ -616,7 +626,11 @@ dns_compare_name(const char *query, struct pbuf *p, u16_t start_offset)
}
} while (n != 0);
- return response_offset + 1;
+ if (response_offset == 0xFFFF) {
+ /* would overflow */
+ return 0xFFFF;
+ }
+ return (uint16_t)(response_offset + 1);
}
/**
