[Asterisk-code-review] Astobj2: Ensure all calls to adjust lock pass a valid object. (asterisk[13])

Corey Farrell asteriskteam at digium.com
Wed Apr 22 15:42:02 CDT 2015


Corey Farrell has uploaded a new change for review.

  https://gerrit.asterisk.org/221

Change subject: Astobj2: Ensure all calls to __adjust_lock pass a valid object.
......................................................................

Astobj2: Ensure all calls to __adjust_lock pass a valid object.

__adjust_lock doesn't check for invalid objects, and doesn't have an
appropriate return value for invalid objects.  Most callers of
__adjust_lock pass objects that have already been confirmed valid,
this change adds checks before the remaining calls.

ASTERISK-24997 #close
Reported by: Corey Farrell

Change-Id: I669100f87937cc3f867cec56a27ae9c01292908f
---
M main/astobj2_container.c
M main/astobj2_hash.c
M main/astobj2_private.h
M main/astobj2_rbtree.c
4 files changed, 21 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/221/1

diff --git a/main/astobj2_container.c b/main/astobj2_container.c
index dc6f5e5..8b8067b 100644
--- a/main/astobj2_container.c
+++ b/main/astobj2_container.c
@@ -510,6 +510,11 @@
 
 void ao2_iterator_restart(struct ao2_iterator *iter)
 {
+	if (!is_ao2_object(iter->c)) {
+		ast_assert(0);
+		return;
+	}
+
 	/* Release the last container node reference if we have one. */
 	if (iter->last_node) {
 		enum ao2_lock_req orig_lock;
diff --git a/main/astobj2_hash.c b/main/astobj2_hash.c
index 37d4b60..cecc5e1 100644
--- a/main/astobj2_hash.c
+++ b/main/astobj2_hash.c
@@ -186,6 +186,13 @@
 		 * same node.
 		 */
 		my_container = (struct ao2_container_hash *) doomed->common.my_container;
+
+		if (!is_ao2_object(my_container)) {
+			ast_log(LOG_ERROR, "Container is not valid.\n");
+			ast_assert(0);
+			return;
+		}
+
 		__adjust_lock(my_container, AO2_LOCK_REQ_WRLOCK, 1);
 
 #if defined(AO2_DEBUG)
diff --git a/main/astobj2_private.h b/main/astobj2_private.h
index 0583faf..d7b1930 100644
--- a/main/astobj2_private.h
+++ b/main/astobj2_private.h
@@ -44,6 +44,8 @@
 #endif	/* defined(AO2_DEBUG) */
 
 int is_ao2_object(void *user_data);
+
+/* user_data must be a valid AO2 object */
 enum ao2_lock_req __adjust_lock(void *user_data, enum ao2_lock_req lock_how, int keep_stronger);
 
 #endif /* ASTOBJ2_PRIVATE_H_ */
diff --git a/main/astobj2_rbtree.c b/main/astobj2_rbtree.c
index 2e3a73e..7bbedcb 100644
--- a/main/astobj2_rbtree.c
+++ b/main/astobj2_rbtree.c
@@ -878,6 +878,13 @@
 		 * same node.
 		 */
 		my_container = (struct ao2_container_rbtree *) doomed->common.my_container;
+
+		if (!is_ao2_object(my_container)) {
+			ast_log(LOG_ERROR, "Container is not valid.\n");
+			ast_assert(0);
+			return;
+		}
+
 		__adjust_lock(my_container, AO2_LOCK_REQ_WRLOCK, 1);
 
 #if defined(AO2_DEBUG)

-- 
To view, visit https://gerrit.asterisk.org/221
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I669100f87937cc3f867cec56a27ae9c01292908f
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Corey Farrell <git at cfware.com>



More information about the asterisk-code-review mailing list