Commit 2c420d4a authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

[PATCH] Use before initialisation in devfs_mk_cdev()

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.
parent a26698b4
...@@ -1445,12 +1445,6 @@ int devfs_mk_bdev(dev_t dev, umode_t mode, const char *fmt, ...) ...@@ -1445,12 +1445,6 @@ int devfs_mk_bdev(dev_t dev, umode_t mode, const char *fmt, ...)
va_list args; va_list args;
int error, n; 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); va_start(args, fmt);
n = vsnprintf(buf, 64, fmt, args); n = vsnprintf(buf, 64, fmt, args);
if (n >= 64 || !buf[0]) { if (n >= 64 || !buf[0]) {
...@@ -1458,6 +1452,12 @@ int devfs_mk_bdev(dev_t dev, umode_t mode, const char *fmt, ...) ...@@ -1458,6 +1452,12 @@ int devfs_mk_bdev(dev_t dev, umode_t mode, const char *fmt, ...)
__FUNCTION__); __FUNCTION__);
return -EINVAL; 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); de = _devfs_prepare_leaf(&dir, buf, mode);
if (!de) { if (!de) {
...@@ -1491,12 +1491,6 @@ int devfs_mk_cdev(dev_t dev, umode_t mode, const char *fmt, ...) ...@@ -1491,12 +1491,6 @@ int devfs_mk_cdev(dev_t dev, umode_t mode, const char *fmt, ...)
va_list args; va_list args;
int error, n; 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); va_start(args, fmt);
n = vsnprintf(buf, 64, fmt, args); n = vsnprintf(buf, 64, fmt, args);
if (n >= 64 || !buf[0]) { if (n >= 64 || !buf[0]) {
...@@ -1505,6 +1499,12 @@ int devfs_mk_cdev(dev_t dev, umode_t mode, const char *fmt, ...) ...@@ -1505,6 +1499,12 @@ int devfs_mk_cdev(dev_t dev, umode_t mode, const char *fmt, ...)
return -EINVAL; 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); de = _devfs_prepare_leaf(&dir, buf, mode);
if (!de) { if (!de) {
printk(KERN_WARNING "%s: could not prepare leaf for %s\n", printk(KERN_WARNING "%s: could not prepare leaf for %s\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment