[PATCH] obj: Fix dereference before NULL check

Tobias Klauser tklauser at distanz.ch
Tue Jun 3 01:47:48 PDT 2014


The check for !obj indicates that obj might be NULL, thus move the call
to obj_ops(obj) - which dereferences obj - after the check.

Signed-off-by: Tobias Klauser <tklauser at distanz.ch>
---
 lib/object.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/object.c b/lib/object.c
index c3751a6..405912b 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -110,13 +110,14 @@ struct nl_derived_object {
 struct nl_object *nl_object_clone(struct nl_object *obj)
 {
 	struct nl_object *new;
-	struct nl_object_ops *ops = obj_ops(obj);
+	struct nl_object_ops *ops;
 	int doff = offsetof(struct nl_derived_object, data);
 	int size;
 
 	if (!obj)
 		return NULL;
 
+	ops = obj_ops(obj);
 	new = nl_object_alloc(ops);
 	if (!new)
 		return NULL;
-- 
1.7.9.5





More information about the libnl mailing list