patch-1.3.86 linux/net/ipv4/ip_masq_app.c

Next file: linux/net/ipv4/ip_masq_ftp.c
Previous file: linux/net/ipv4/ip_masq.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.85/linux/net/ipv4/ip_masq_app.c linux/net/ipv4/ip_masq_app.c
@@ -487,14 +487,26 @@
 
 static struct sk_buff * skb_replace(struct sk_buff *skb, int pri, char *o_buf, int o_len, char *n_buf, int n_len)
 {
-        int diff, o_offset;
+        int maxsize, diff, o_offset;
         struct sk_buff *n_skb;
 
+	maxsize = skb->truesize - sizeof(struct sk_buff);
+
         diff = n_len - o_len;
         o_offset = o_buf - (char*) skb->data;
 
-        if (diff != 0)  {
-                
+	if (maxsize <= n_len) {
+	    if (diff != 0) {
+		memcpy(skb->data + o_offset + n_len,o_buf + o_len,
+		       skb->len - (o_offset + o_len));
+	    }
+
+	    memcpy(skb->data + o_offset, n_buf, n_len);
+
+	    n_skb    = skb;
+	    skb->len = n_len;
+	    skb->end = skb->head+n_len;
+	} else {
                 /*
                  * 	Sizes differ, make a copy
                  */
@@ -526,14 +538,6 @@
                  */
                 
                 kfree_skb(skb, FREE_WRITE);
-                
-        } else {
-                
-                /*
-                 *	Same len, just copy
-                 */
-                n_skb = skb;
-                memcpy(n_skb->data + o_offset, n_buf, n_len);
         }
         return n_skb;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this