Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/dns.cpp
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | do { | ||||
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 > MAX_LABEL_LENGTH) { | ||||
return -1; | return -1; | ||||
} | } | ||||
// The maximum size of a query name is 255. The buffer must have | // 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 | // room for the null-character at the end of the buffer after writing | ||||
// the label. | // the label. | ||||
if (octet + bufused > 255) { | if (octet + bufused > MAX_QUERY_NAME_LENGTH) { | ||||
return -1; | return -1; | ||||
} | } | ||||
// copy label | // copy label | ||||
while (octet) { | while (octet) { | ||||
if (*inpos == inend) { | 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; | ||||
} | } | ||||
octet--; | octet--; | ||||
buf[bufused++] = c; | buf[bufused++] = c; | ||||
} | } | ||||
} while (1); | } while (1); | ||||
} | } | ||||
// 0: k | // 0: ok | ||||
// -1: component > 63 characters | // -1: label > MAX_LABEL_LENGTH characters | ||||
// -2: insufficent space in output | // -2: insufficent space in output | ||||
// -3: two subsequent dots | // -3: two subsequent dots | ||||
static int write_name(uint8_t **outpos, const uint8_t *outend, const char *name, | static int write_name(uint8_t **outpos, const uint8_t *outend, const char *name, | ||||
int offset) { | int offset) { | ||||
while (*name != 0) { | while (*name != 0) { | ||||
const char *dot = strchr(name, '.'); | const char *dot = strchr(name, '.'); | ||||
const char *fin = dot; | const char *fin = dot; | ||||
if (!dot) { | if (!dot) { | ||||
fin = name + strlen(name); | fin = name + strlen(name); | ||||
} | } | ||||
if (fin - name > 63) { | if (fin - name > MAX_LABEL_LENGTH) { | ||||
return -1; | return -1; | ||||
} | } | ||||
if (fin == name) { | if (fin == name) { | ||||
return -3; | return -3; | ||||
} | } | ||||
if (outend - *outpos < fin - name + 2) { | if (outend - *outpos < fin - name + 2) { | ||||
return -2; | return -2; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 265 Lines • ▼ Show 20 Lines | if (nquestion > 1) { | ||||
/* fprintf(stdout, "Multiple questions %i?\n", nquestion); */ | /* fprintf(stdout, "Multiple questions %i?\n", nquestion); */ | ||||
responseCode = DNSResponseCode::NOT_IMPLEMENTED; | responseCode = DNSResponseCode::NOT_IMPLEMENTED; | ||||
goto error; | goto error; | ||||
} | } | ||||
{ | { | ||||
const uint8_t *inpos = inbuf + 12; | const uint8_t *inpos = inbuf + 12; | ||||
const uint8_t *inend = inbuf + insize; | const uint8_t *inend = inbuf + insize; | ||||
char name[256]; | char name[MAX_QUERY_NAME_BUFFER_LENGTH]; | ||||
int offset = inpos - inbuf; | int offset = inpos - inbuf; | ||||
int ret = parse_name(&inpos, inend, inbuf, name, 256); | int ret = parse_name(&inpos, inend, inbuf, name, | ||||
MAX_QUERY_NAME_BUFFER_LENGTH); | |||||
if (ret == -1) { | if (ret == -1) { | ||||
responseCode = DNSResponseCode::FORMAT_ERROR; | responseCode = DNSResponseCode::FORMAT_ERROR; | ||||
goto error; | goto error; | ||||
} | } | ||||
if (ret == -2) { | if (ret == -2) { | ||||
responseCode = DNSResponseCode::REFUSED; | responseCode = DNSResponseCode::REFUSED; | ||||
goto error; | goto error; | ||||
▲ Show 20 Lines • Show All 246 Lines • Show Last 20 Lines |