--- a/src/defrag.c +++ b/src/defrag.c @@ -690,8 +690,12 @@ } ltrim = prev_end - frag_offset; - if ((next != NULL) && (frag_end > next->offset)) { - next->ltrim = frag_end - next->offset; + for (Frag *n = next; n != NULL && frag_end > n->offset; + n = IP_FRAGMENTS_RB_NEXT(n)) { + if (frag_end >= n->offset + n->data_len) + n->skip = 1; + else + n->ltrim = frag_end - n->offset; } goto insert; @@ -712,8 +716,12 @@ } } - if ((next != NULL) && (frag_end > next->offset)) { - next->ltrim = frag_end - next->offset; + for (Frag *n = next; n != NULL && frag_end > n->offset; + n = IP_FRAGMENTS_RB_NEXT(n)) { + if (frag_end >= n->offset + n->data_len) + n->skip = 1; + else + n->ltrim = frag_end - n->offset; } goto insert;