Skip to content

Commit dd38491

Browse files
authored
Fix bounds check in CacheVC::scanObject (#13263)
1 parent 36b8649 commit dd38491

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/iocore/cache/CacheVC.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,17 @@ CacheVC::scanObject(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
766766
}
767767
break;
768768
}
769-
if (doc->data() - buf->data() > static_cast<int>(io.aiocb.aio_nbytes)) {
770-
might_need_overlap_read = true;
771-
goto Lskip;
769+
{
770+
size_t const doc_off = reinterpret_cast<char *>(doc) - buf->data();
771+
// Bounds-check in unsigned domain: doc must lie within the
772+
// buffer, with room for the Doc header, and doc->hlen must
773+
// fit in the remaining bytes before doc->hdr() and
774+
// HTTPInfo::unmarshal walk it.
775+
if (io.aiocb.aio_nbytes < doc_off || (io.aiocb.aio_nbytes - doc_off) < sizeof(Doc) ||
776+
(io.aiocb.aio_nbytes - doc_off - sizeof(Doc)) < doc->hlen) {
777+
might_need_overlap_read = true;
778+
goto Lskip;
779+
}
772780
}
773781
{
774782
char *tmp = doc->hdr();

0 commit comments

Comments
 (0)