diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index 7ee26d9f..1dd2f7f5 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -998,6 +998,9 @@ static int parse_rr(const unsigned char *buf, const unsigned char *start,
 	if ((offset + *rdlen) > *response_size)
 		return -ENOBUFS;
 
+	if ((*end + *rdlen) > max)
+		return -EINVAL;
+
 	memcpy(response + offset, *end, *rdlen);
 
 	*end += *rdlen;
