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

Matt Jordan asteriskteam at digium.com
Thu Apr 23 06:50:52 CDT 2015


Matt Jordan has submitted this change and it was merged.

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_rbtree.c
3 files changed, 10 insertions(+), 0 deletions(-)

Approvals:
  Matt Jordan: Looks good to me, approved; Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/main/astobj2_container.c b/main/astobj2_container.c
index d0abc79..07d10b9 100644
--- a/main/astobj2_container.c
+++ b/main/astobj2_container.c
@@ -510,6 +510,12 @@
 
 void ao2_iterator_restart(struct ao2_iterator *iter)
 {
+	if (!is_ao2_object(iter->c)) {
+		ast_log(LOG_ERROR, "Iterator container is not valid.\n");
+		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 76259dc..110dd16 100644
--- a/main/astobj2_hash.c
+++ b/main/astobj2_hash.c
@@ -186,6 +186,8 @@
 		 * same node.
 		 */
 		my_container = (struct ao2_container_hash *) doomed->common.my_container;
+		ast_assert(is_ao2_object(my_container));
+
 		__adjust_lock(my_container, AO2_LOCK_REQ_WRLOCK, 1);
 
 #if defined(AO2_DEBUG)
diff --git a/main/astobj2_rbtree.c b/main/astobj2_rbtree.c
index a069c40..d3a9025 100644
--- a/main/astobj2_rbtree.c
+++ b/main/astobj2_rbtree.c
@@ -878,6 +878,8 @@
 		 * same node.
 		 */
 		my_container = (struct ao2_container_rbtree *) doomed->common.my_container;
+		ast_assert(is_ao2_object(my_container));
+
 		__adjust_lock(my_container, AO2_LOCK_REQ_WRLOCK, 1);
 
 #if defined(AO2_DEBUG)

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I669100f87937cc3f867cec56a27ae9c01292908f
Gerrit-PatchSet: 4
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-code-review mailing list