X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=modules%2Fbsd-comp.c;h=b730c0738953b89040ef4c2b5ed35d1d46c90d32;hb=9faea8a8533fe693a25a2bec728c969099809ab7;hp=a9852789534174d546c269920ce6d856689403f8;hpb=7aa1222ea5fe1d3459c9cb31c2dc41d2f3826554;p=ppp.git diff --git a/modules/bsd-comp.c b/modules/bsd-comp.c index a985278..b730c07 100644 --- a/modules/bsd-comp.c +++ b/modules/bsd-comp.c @@ -39,6 +39,8 @@ /* * This version is for use with STREAMS under SunOS 4.x. + * + * $Id: bsd-comp.c,v 1.3 1994/08/31 23:58:53 paulus Exp $ */ #include @@ -492,20 +494,22 @@ bsd_compress(state, mret, mp, slen, maxolen) wptr = cp_end = NULL; olen = 0; - /* Copy the PPP header over, changing the protocol */ - if (wptr) { - *wptr++ = rptr[0]; /* assumes the ppp header is */ - *wptr++ = rptr[1]; /* all in one mblk */ - *wptr++ = 0; /* change the protocol */ - *wptr++ = PPP_COMP; - } - - /* install the 3-byte sequence number */ + /* + * Copy the PPP header over, changing the protocol, + * and install the 3-byte sequence number. + */ slen += db->seqno - PPP_HDRLEN + 1; db->seqno = slen; - *wptr++ = slen>>16; - *wptr++ = slen>>8; - *wptr++ = slen; + if (wptr) { + wptr[0] = rptr[0]; /* assumes the ppp header is */ + wptr[1] = rptr[1]; /* all in one mblk */ + wptr[2] = 0; /* change the protocol */ + wptr[3] = PPP_COMP; + wptr[4] = slen>>16; + wptr[5] = slen>>8; + wptr[6] = slen; + wptr += PPP_HDRLEN + BSD_OVHD; + } /* start with the protocol byte */ ent = rptr[3]; @@ -767,10 +771,13 @@ bsd_decompress(state, cmsg, hdroff) rptr += 3; len = cmsg->b_wptr - rptr; - /* check the sequence number and give up if the length is nonsense */ + /* + * Check the sequence number and give up if the length is nonsense. + * The check is against mru+1 because we compress one byte of protocol. + */ explen = (seq - db->seqno) & 0xffffff; db->seqno = seq; - if (explen > db->mru || explen < 1) { + if (explen > db->mru + 1 || explen < 1) { if (db->debug) printf("bsd_decomp%d: bad length 0x%x\n", db->unit, explen); return 0;