summaryrefslogtreecommitdiff
path: root/util/data/msgencode.c
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2018-05-12 11:54:35 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2018-05-12 11:54:35 +0000
commit15de2de8449b4f5063f93578ae68aa0bc79a205c (patch)
treef0a7e3230212205e7ff88a2900de97026940f63c /util/data/msgencode.c
parent689b65913bba5320ef50befddf4743c6dafde873 (diff)
Notes
Diffstat (limited to 'util/data/msgencode.c')
-rw-r--r--util/data/msgencode.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/util/data/msgencode.c b/util/data/msgencode.c
index 1f72a03b8c64..aab7f5dfecba 100644
--- a/util/data/msgencode.c
+++ b/util/data/msgencode.c
@@ -647,6 +647,8 @@ reply_info_encode(struct query_info* qinfo, struct reply_info* rep,
sldns_buffer_clear(buffer);
if(udpsize < sldns_buffer_limit(buffer))
sldns_buffer_set_limit(buffer, udpsize);
+ else if(sldns_buffer_limit(buffer) < udpsize)
+ udpsize = sldns_buffer_limit(buffer);
if(sldns_buffer_remaining(buffer) < LDNS_HEADER_SIZE)
return 0;
@@ -810,7 +812,7 @@ reply_info_answer_encode(struct query_info* qinf, struct reply_info* rep,
struct edns_data* edns, int dnssec, int secure)
{
uint16_t flags;
- int attach_edns = 1;
+ unsigned int attach_edns = 0;
if(!cached || rep->authoritative) {
/* original flags, copy RD and CD bits from query. */
@@ -833,12 +835,15 @@ reply_info_answer_encode(struct query_info* qinf, struct reply_info* rep,
log_assert(flags & BIT_QR); /* QR bit must be on in our replies */
if(udpsize < LDNS_HEADER_SIZE)
return 0;
+ if(sldns_buffer_capacity(pkt) < udpsize)
+ udpsize = sldns_buffer_capacity(pkt);
if(udpsize < LDNS_HEADER_SIZE + calc_edns_field_size(edns)) {
/* packet too small to contain edns, omit it. */
attach_edns = 0;
} else {
/* reserve space for edns record */
- udpsize -= calc_edns_field_size(edns);
+ attach_edns = (unsigned int)calc_edns_field_size(edns);
+ udpsize -= attach_edns;
}
if(!reply_info_encode(qinf, rep, id, flags, pkt, timenow, region,
@@ -846,7 +851,8 @@ reply_info_answer_encode(struct query_info* qinf, struct reply_info* rep,
log_err("reply encode: out of memory");
return 0;
}
- if(attach_edns)
+ if(attach_edns && sldns_buffer_capacity(pkt) >=
+ sldns_buffer_limit(pkt)+attach_edns)
attach_edns_record(pkt, edns);
return 1;
}