Skip to content

Commit 126c04a

Browse files
committed
Fix heap overflow in ip_reass on big packet input
When the first fragment does not fit in the preallocated buffer, q will already be pointing to the ext buffer, so we mustn't try to update it. Signed-off-by: Samuel Thibault <[email protected]>
1 parent 113a219 commit 126c04a

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/ip_input.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ static struct ip *ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp)
326326
q = fp->frag_link.next;
327327
m = dtom(slirp, q);
328328

329+
int was_ext = m->m_flags & M_EXT;
330+
329331
q = (struct ipasfrag *)q->ipf_next;
330332
while (q != (struct ipasfrag *)&fp->frag_link) {
331333
struct mbuf *t = dtom(slirp, q);
@@ -348,7 +350,7 @@ static struct ip *ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp)
348350
* the old buffer (in the mbuf), so we must point ip
349351
* into the new buffer.
350352
*/
351-
if (m->m_flags & M_EXT) {
353+
if (!was_ext && m->m_flags & M_EXT) {
352354
int delta = (char *)q - m->m_dat;
353355
q = (struct ipasfrag *)(m->m_ext + delta);
354356
}

0 commit comments

Comments
 (0)