Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/dns.cpp
Show First 20 Lines • Show All 72 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) { | ||||
if (bufused > 253) { | |||||
jasonbcox: Just checking my understanding here: there needs to be at least 2 free units for the '.' and a… | |||||
nakihitoAuthorUnsubmitted Done Inline ActionsThis is basically correct. The buffer is also null-terminated when returning successfully. I'll add a comment clarifying this. nakihito: This is basically correct. The buffer is also null-terminated when returning successfully. | |||||
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 | ||||
Show All 9 Lines | do { | ||||
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; | ||||
} | } | ||||
// copy label | // copy label | ||||
while (octet) { | while (octet) { | ||||
if (*inpos == inend) { | if (*inpos == inend || bufused > 254) { | ||||
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 |
Just checking my understanding here: there needs to be at least 2 free units for the '.' and a following non-dot character?
Either way, a comment explaining how this value was chosen would be helpful, since it's not obvious at a glance.