Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/dns.cpp
Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | do { | ||||
// read length of next component | // read length of next component | ||||
int octet = *((*inpos)++); | int octet = *((*inpos)++); | ||||
if (octet == 0) { | if (octet == 0) { | ||||
buf[bufused] = 0; | buf[bufused] = 0; | ||||
return 0; | return 0; | ||||
} | } | ||||
// add dot in output | // add dot in output | ||||
if (!init) { | if (!init) { | ||||
// The maximum size of a query name is 255. The buffer must have | |||||
// room for at least the '.' and a valid non-'.' character | |||||
if (bufused > 253) { | |||||
return -1; | |||||
} | |||||
if (bufused == bufsize - 1) { | if (bufused == bufsize - 1) { | ||||
return -2; | return -2; | ||||
} | } | ||||
buf[bufused++] = '.'; | buf[bufused++] = '.'; | ||||
} else { | } else { | ||||
init = 0; | init = 0; | ||||
} | } | ||||
// handle references | // handle references | ||||
if ((octet & 0xC0) == 0xC0) { | if ((octet & 0xC0) == 0xC0) { | ||||
if (*inpos == inend) { | if (*inpos == inend) { | ||||
return -1; | return -1; | ||||
} | } | ||||
int ref = ((octet - 0xC0) << 8) + *((*inpos)++); | int ref = ((octet - 0xC0) << 8) + *((*inpos)++); | ||||
if (ref < 0 || ref >= (*inpos) - inbuf - 2) { | if (ref < 0 || ref >= (*inpos) - inbuf - 2) { | ||||
return -1; | return -1; | ||||
} | } | ||||
const uint8_t *newbuf = inbuf + ref; | const uint8_t *newbuf = inbuf + ref; | ||||
return parse_name(&newbuf, (*inpos) - 2, inbuf, buf + bufused, | return parse_name(&newbuf, (*inpos) - 2, inbuf, buf + bufused, | ||||
bufsize - bufused); | bufsize - bufused); | ||||
} | } | ||||
if (octet > 63) { | if (octet > 63) { | ||||
return -1; | return -1; | ||||
} | } | ||||
// The maximum size of a query name is 255. The buffer must have | |||||
// room for the null-character at the end of the buffer after writing | |||||
// the label. | |||||
if (octet + bufused > 255) { | |||||
return -1; | |||||
} | |||||
// copy label | // copy label | ||||
while (octet) { | while (octet) { | ||||
if (*inpos == inend || bufused > 254) { | if (*inpos == inend) { | ||||
return -1; | return -1; | ||||
} | } | ||||
if (bufused == bufsize - 1) { | if (bufused == bufsize - 1) { | ||||
return -2; | return -2; | ||||
} | } | ||||
int c = *((*inpos)++); | int c = *((*inpos)++); | ||||
if (c == '.') { | if (c == '.') { | ||||
return -1; | return -1; | ||||
▲ Show 20 Lines • Show All 558 Lines • Show Last 20 Lines |