chiark / gitweb /
SECURITY: Defend adns_rr_info (somewhat) from bogus *datap
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 Dec 2016 14:51:54 +0000 (14:51 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 26 May 2020 19:09:36 +0000 (20:09 +0100)
commit37792aacaf7abbcdac6a02715a5ef794b5147f13
treea29fd8686068719ebfe8f9b329c89b8e56eb213b
parent54d811a530e9cf16148998cd9fdd168dbf8e14d5
SECURITY: Defend adns_rr_info (somewhat) from bogus *datap

The general pattern for formatting integers is to sprintf into a
fixed-size buffer.  This is correct if the input is in the right
range; if it isn't, the buffer may be overrun (depending on the sizes
of the types on the current platform).

Of course the inputs ought to be right.  And there are pointers in
there too, so perhaps we could say that the caller ought to check
these things.  I think it's better to require the caller to make the
pointer structure right, but to have the code here be defensive about
(and tolerate with an erro but without crashing) out-of-range integer
values.

So: defend each of these integer conversion sites with a check for the
actual permitted range, and return adns_s_invaliddata if not.

The lack of this check causes the SOA sign extension bug to be a
serious security problem: the sign extended SOA value is out of range,
and will overrun the buffer when reconverted.

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

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