chiark / gitweb /
SECURITY: Do not overrun reading buffer if domain ends with backslash
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 5 Dec 2016 22:47:34 +0000 (22:47 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 26 May 2020 19:11:40 +0000 (20:11 +0100)
If the query domain ended with \, and adns_qf_quoteok_query was
specified, qdparselabel would read additional bytes from the buffer
and try to treat them as the escape sequence.  It would depart the
input buffer and start processing many bytes of arbitrary heap data as
if it were the query domain.

Eventually it would run out of input or find some other kind of error,
and declare the query domain invalid.  But before then it might outrun
available memory and crash.

In principle this could be a denial of service attack.

Found by AFL 2.35b.  CVE-2017-9107.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/transmit.c

index 33c33297c8b248329f212a91ce987be7d84f79dd..498498602f7514885af5642c56b9cb17b38a7a6a 100644 (file)
@@ -87,6 +87,7 @@ static adns_status qdparselabel(adns_state ads,
   while (p!=pe && (c= *p++)!='.') {
     if (c=='\\') {
       if (!(flags & adns_qf_quoteok_query)) return adns_s_querydomaininvalid;
+      if (p==pe) return adns_s_querydomaininvalid;
       if (ctype_digit(p[0])) {
        if (p+1==pe || p+2==pe) return adns_s_querydomaininvalid;
        if (ctype_digit(p[1]) && ctype_digit(p[2])) {