- if (m->m_len < off + sizeof(struct ipcomp)) {
- m = m_pullup(m, off + sizeof(struct ipcomp));
- if (!m) {
- ipseclog((LOG_DEBUG, "IPv4 IPComp input: can't pullup;"
- "dropping the packet for simplicity\n"));
- ipsecstat.in_nomem++;
- goto fail;
- }
- } else if (m->m_len > off + sizeof(struct ipcomp)) {
- /* chop header part from the packet header chain */
- struct mbuf *n;
- MGETHDR(n, M_DONTWAIT, MT_HEADER);
- if (!n) {
- ipsecstat.in_nomem++;
- goto fail;
- }
- M_COPY_PKTHDR(n, m);
- MH_ALIGN(n, off + sizeof(struct ipcomp));
- n->m_len = off + sizeof(struct ipcomp);
- bcopy(mtod(m, caddr_t), mtod(n, caddr_t),
- off + sizeof(struct ipcomp));
- m_adj(m, off + sizeof(struct ipcomp));
- m->m_flags &= ~M_PKTHDR;
- n->m_next = m;
- m = n;
+
+ md = m_pulldown(m, off, sizeof(*ipcomp), NULL);
+ if (!md) {
+ m = NULL; /*already freed*/
+ ipseclog((LOG_DEBUG, "IPv4 IPComp input: assumption failed "
+ "(pulldown failure)\n"));
+ IPSEC_STAT_INCREMENT(ipsecstat.in_inval);
+ goto fail;