]> git.karo-electronics.de Git - linux-beck.git/commitdiff
device property: avoid allocations of 0 length
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 29 Dec 2015 11:07:50 +0000 (13:07 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 1 Jan 2016 01:09:51 +0000 (02:09 +0100)
Arrays can not have zero elements by definition of the unified device
properties. If such property comes from outside we should not allow it to pass.
Otherwise memory allocation on 0 length will return non-NULL value, which we
currently don't check.

Prevent memory allocations of 0 length.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/property.c

index b3429cc4ee63da94ac69df5d83dc05bd5a5980b3..c359351d50f1c99e9758b74ea84d97e76b402b0f 100644 (file)
@@ -653,6 +653,9 @@ int fwnode_property_match_string(struct fwnode_handle *fwnode,
        if (nval < 0)
                return nval;
 
+       if (nval == 0)
+               return -ENODATA;
+
        values = kcalloc(nval, sizeof(*values), GFP_KERNEL);
        if (!values)
                return -ENOMEM;
@@ -718,6 +721,9 @@ static int pset_copy_entry(struct property_entry *dst,
                return -ENOMEM;
 
        if (src->is_array) {
+               if (!src->length)
+                       return -ENODATA;
+
                if (src->is_string) {
                        nval = src->length / sizeof(const char *);
                        dst->pointer.str = kcalloc(nval, sizeof(const char *),