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@xxxxxxxxx> --- Cc: barebox@xxxxxxxxxxxxxxxxxxx --- 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 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox