]> git.hungrycats.org Git - linux/commitdiff
[PATCH] Use before initialisation in devfs_mk_cdev()
authorChristoph Hellwig <hch@infradead.org>
Fri, 18 Jul 2003 13:00:06 +0000 (06:00 -0700)
committerLinus Torvalds <torvalds@home.osdl.org>
Fri, 18 Jul 2003 13:00:06 +0000 (06:00 -0700)
As noted by Gergely Nagy:

  "devfs_mk_cdev() first checks the mode passed to it, and if it thinks
   it is not a char device, it prints a warning and aborts.  Now, this
   printing involves the local variable `buf' (char buf[64]), which is
   not initialised at that point."

The same problem also affects devfs_mk_bdev.

Fixed thus.

fs/devfs/base.c

index 54a3e5a9dc4929783cbeb7322af0ca4e86ea3b64..060f20ef11f16f40ac2da3ddbe09eba659b5aa4b 100644 (file)
@@ -1445,12 +1445,6 @@ int devfs_mk_bdev(dev_t dev, umode_t mode, const char *fmt, ...)
        va_list args;
        int error, n;
 
-       if (!S_ISBLK(mode)) {
-               printk(KERN_WARNING "%s: invalide mode (%u) for %s\n",
-                               __FUNCTION__, mode, buf);
-               return -EINVAL;
-       }
-
        va_start(args, fmt);
        n = vsnprintf(buf, 64, fmt, args);
        if (n >= 64 || !buf[0]) {
@@ -1458,6 +1452,12 @@ int devfs_mk_bdev(dev_t dev, umode_t mode, const char *fmt, ...)
                                __FUNCTION__);
                return -EINVAL;
        }
+       
+       if (!S_ISBLK(mode)) {
+               printk(KERN_WARNING "%s: invalide mode (%u) for %s\n",
+                               __FUNCTION__, mode, buf);
+               return -EINVAL;
+       }
 
        de = _devfs_prepare_leaf(&dir, buf, mode);
        if (!de) {
@@ -1491,12 +1491,6 @@ int devfs_mk_cdev(dev_t dev, umode_t mode, const char *fmt, ...)
        va_list args;
        int error, n;
 
-       if (!S_ISCHR(mode)) {
-               printk(KERN_WARNING "%s: invalide mode (%u) for %s\n",
-                               __FUNCTION__, mode, buf);
-               return -EINVAL;
-       }
-
        va_start(args, fmt);
        n = vsnprintf(buf, 64, fmt, args);
        if (n >= 64 || !buf[0]) {
@@ -1505,6 +1499,12 @@ int devfs_mk_cdev(dev_t dev, umode_t mode, const char *fmt, ...)
                return -EINVAL;
        }
 
+       if (!S_ISCHR(mode)) {
+               printk(KERN_WARNING "%s: invalide mode (%u) for %s\n",
+                               __FUNCTION__, mode, buf);
+               return -EINVAL;
+       }
+
        de = _devfs_prepare_leaf(&dir, buf, mode);
        if (!de) {
                printk(KERN_WARNING "%s: could not prepare leaf for %s\n",