PATCH 2.4.21 nfsroot.c buffercheck

Walter Harms (Walter.Harms@Informatik.Uni-Oldenburg.DE)
Sat, 5 Jul 2003 19:24:01 +0200 (MEST)


Hi Liste,
this patches fixes a wrong bordercheck and simplifies it.
Strings with NFS_MAXPATHLEN would pass in the old code.

walter

--- fs/nfs/nfsroot.c.org 2003-07-03 23:23:18.000000000 +0200
+++ fs/nfs/nfsroot.c 2003-07-03 23:36:51.000000000 +0200
@@ -207,7 +207,8 @@
{
char buf[NFS_MAXPATHLEN];
char *cp;
-
+ int ret;
+
/* Set some default values */
memset(&nfs_data, 0, sizeof(nfs_data));
nfs_port = -1;
@@ -230,14 +231,15 @@
/* Override them by options set on kernel command-line */
root_nfs_parse(name, buf);

- cp = system_utsname.nodename;
- if (strlen(buf) + strlen(cp) > NFS_MAXPATHLEN) {
- printk(KERN_ERR "Root-NFS: Pathname for remote directory too long.\n");
- return -1;
- }
- sprintf(nfs_path, buf, cp);
+ ret=snprintf(nfs_path,NFS_MAXPATHLEN, buf, system_utsname.nodename);

- return 1;
+ if (ret < NFS_MAXPATHLEN)
+ return 1;
+ else {
+ printk(KERN_ERR "Root-NFS: Pathname for remote directory too long.\n");
+ return -1;
+ }
+
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/