Skip to content
Snippets Groups Projects
Commit a78db27a authored by Lubos Slovak's avatar Lubos Slovak
Browse files

Fixed setting of max packet size to response.

- If both max size and OPT RR are given, the payload in the OPT RR
  cannot be larger than the max size - added check.
- Fixed API of response_add_opt().
- Disabled reallocation in response_add_opt() - larger size in OPT
  RR should not override the max size already set (max size is
  more important).

refs #769
parent bf9cde3c
Branches
Tags
No related merge requests found
......@@ -18,5 +18,6 @@ const error_table_t dnslib_error_msgs[DNSLIB_ERROR_COUNT] = {
{DNSLIB_EZONEIN, "Error inserting zone."},
{DNSLIB_ENOZONE, "No such zone found."},
{DNSLIB_EDNAMEPTR, "Domain name pointer larger than allowed."},
{DNSLIB_EPAYLOAD, "Payload in OPT RR larger than max wire size."},
{DNSLIB_ERROR, 0}
};
......@@ -30,8 +30,9 @@ enum dnslib_error {
DNSLIB_EZONEIN, /*!< Error inserting zone. */
DNSLIB_ENOZONE, /*!< No such zone found. */
DNSLIB_EDNAMEPTR, /*!< Domain name pointer larger than allowed. */
DNSLIB_EPAYLOAD, /*!< Payload in OPT RR larger than max wire size. */
DNSLIB_ERROR_COUNT = 15
DNSLIB_ERROR_COUNT = 16
};
/*! \brief Table linking error messages to error codes. */
......
......@@ -247,6 +247,10 @@ static int dnslib_response_init(dnslib_response_t *resp,
resp->edns_response.payload = opt_rr->payload;
resp->edns_response.size = opt_rr->size;
if (max_size > 0 && max_size < opt_rr->payload) {
return DNSLIB_EPAYLOAD;
}
resp->max_size = resp->edns_response.payload;
}
......@@ -1368,20 +1372,27 @@ int dnslib_response_add_opt(dnslib_response_t *resp,
resp->edns_response.payload = opt_rr->payload;
resp->edns_response.size = opt_rr->size;
if (resp->max_size < resp->edns_response.payload) {
// reallocate space for the wire format (and copy anything
// that might have been there before
uint8_t *wire_new = (uint8_t *)malloc(
resp->edns_response.payload);
if (wire_new == NULL) {
return DNSLIB_ENOMEM;
}
// if max size is set, it means there is some reason to be that way,
// so we can't just set it to higher value
memcpy(wire_new, resp->wireformat, resp->max_size);
resp->wireformat = wire_new;
if (resp->max_size > 0 && resp->max_size < opt_rr->payload) {
return DNSLIB_EPAYLOAD;
}
// set max size (should override??)
// if (resp->max_size < resp->edns_response.payload) {
// // reallocate space for the wire format (and copy anything
// // that might have been there before
// uint8_t *wire_new = (uint8_t *)malloc(
// resp->edns_response.payload);
// if (wire_new == NULL) {
// return DNSLIB_ENOMEM;
// }
// memcpy(wire_new, resp->wireformat, resp->max_size);
// resp->wireformat = wire_new;
// }
// set max size (less is OK)
resp->max_size = resp->edns_response.payload;
return DNSLIB_EOK;
......@@ -1407,7 +1418,7 @@ int dnslib_response_set_max_size(dnslib_response_t *resp, int max_size)
resp->wireformat = wire_new;
}
// set max size (should override??)
// set max size
resp->max_size = max_size;
return DNSLIB_EOK;
......
......@@ -177,7 +177,7 @@ void dnslib_response_clear(dnslib_response_t *resp);
*
* \todo Needs test.
*/
int dnslib_response_set_opt(dnslib_response_t *resp,
int dnslib_response_add_opt(dnslib_response_t *resp,
const dnslib_opt_rr_t *opt_rr);
/*!
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment