[PATCH 1/3] OF: base: add sanity checks to of_new/delete_property

Sebastian Hesselbarth sebastian.hesselbarth at gmail.com
Fri Jun 21 11:15:16 EDT 2013


This adds some sanity checks to of_new_property and of_delete_property.
Also, data passed to of_new_property is only copied if non-NULL.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1b351ee..bcfd73a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1527,21 +1527,37 @@ struct property *of_new_property(struct device_node *node, const char *name,
 	struct property *prop;
 
 	prop = xzalloc(sizeof(*prop));
+	if (!prop)
+		return NULL;
 
 	prop->name = strdup(name);
+	if (!prop->name)
+		goto bail_out;
+
 	prop->length = len;
 	if (len) {
 		prop->value = xzalloc(len);
-		memcpy(prop->value, data, len);
+		if (!prop->value)
+			goto bail_out;
 	}
 
+	if (len && data)
+		memcpy(prop->value, data, len);
+
 	list_add_tail(&prop->list, &node->properties);
 
 	return prop;
+
+bail_out:
+	of_delete_property(prop);
+	return NULL;
 }
 
 void of_delete_property(struct property *pp)
 {
+	if (!pp)
+		return;
+
 	list_del(&pp->list);
 
 	free(pp->name);
-- 
1.7.2.5




More information about the barebox mailing list