@@ -1161,20 +1161,24 @@ size_t mg_dns_parse_rr(const uint8_t *buf, size_t len, size_t ofs,
1161
1161
bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *dm) {
1162
1162
const struct mg_dns_header *h = (struct mg_dns_header *) buf;
1163
1163
struct mg_dns_rr rr;
1164
- size_t i, n, ofs = sizeof(*h);
1164
+ size_t i, n, num_answers, ofs = sizeof(*h);
1165
1165
memset(dm, 0, sizeof(*dm));
1166
1166
1167
1167
if (len < sizeof(*h)) return 0; // Too small, headers dont fit
1168
1168
if (mg_ntohs(h->num_questions) > 1) return 0; // Sanity
1169
- if (mg_ntohs(h->num_answers) > 15) return 0; // Sanity
1169
+ num_answers = mg_ntohs(h->num_answers);
1170
+ if (num_answers > 10) {
1171
+ MG_DEBUG(("Got %u answers, ignoring beyond 10th one", num_answers));
1172
+ num_answers = 10; // Sanity cap
1173
+ }
1170
1174
dm->txnid = mg_ntohs(h->txnid);
1171
1175
1172
1176
for (i = 0; i < mg_ntohs(h->num_questions); i++) {
1173
1177
if ((n = mg_dns_parse_rr(buf, len, ofs, true, &rr)) == 0) return false;
1174
1178
// MG_INFO(("Q %lu %lu %hu/%hu", ofs, n, rr.atype, rr.aclass));
1175
1179
ofs += n;
1176
1180
}
1177
- for (i = 0; i < mg_ntohs(h-> num_answers) ; i++) {
1181
+ for (i = 0; i < num_answers; i++) {
1178
1182
if ((n = mg_dns_parse_rr(buf, len, ofs, false, &rr)) == 0) return false;
1179
1183
// MG_INFO(("A -- %lu %lu %hu/%hu %s", ofs, n, rr.atype, rr.aclass,
1180
1184
// dm->name));
0 commit comments