patch-2.4.5 linux/drivers/net/wan/comx-hw-comx.c

Next file: linux/drivers/net/wan/comx.c
Previous file: linux/drivers/net/tulip/tulip_core.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.4/linux/drivers/net/wan/comx-hw-comx.c linux/drivers/net/wan/comx-hw-comx.c
@@ -1044,10 +1044,20 @@
 		if (!(page = (char *)__get_free_page(GFP_KERNEL))) {
 			return -ENOMEM;
 		}
-		copy_from_user(page, buffer, count = (min(count, PAGE_SIZE)));
-		if (*(page + count - 1) == '\n') {
-			*(page + count - 1) = 0;
+		if(copy_from_user(page, buffer, count = (min(count, PAGE_SIZE))))
+		{
+			count = -EFAULT;
+			goto out;
+		}
+		if (page[count-1] == '\n')
+			page[count-1] = '\0';
+		else if (count < PAGE_SIZE)
+			page[count] = '\0';
+		else if (page[count]) {
+ 			count = -EINVAL;
+			goto out;
 		}
+		page[count]=0;	/* Null terminate */
 	} else {
 		byte *tmp;
 
@@ -1140,7 +1150,7 @@
 			hw->clock = kbps ? COMX_CLOCK_CONST/kbps : 0;
 		}
 	}
-
+out:
 	free_page((unsigned long)page);
 	return count;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)