[svn-commits] rmudgett: branch rmudgett/ao2_red_black r372116 - /team/rmudgett/ao2_red_blac...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Aug 31 10:37:28 CDT 2012


Author: rmudgett
Date: Fri Aug 31 10:37:23 2012
New Revision: 372116

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=372116
Log:
Add integrity checks for container node pointers to self.

Modified:
    team/rmudgett/ao2_red_black/main/astobj2.c

Modified: team/rmudgett/ao2_red_black/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ao2_red_black/main/astobj2.c?view=diff&rev=372116&r1=372115&r2=372116
==============================================================================
--- team/rmudgett/ao2_red_black/main/astobj2.c (original)
+++ team/rmudgett/ao2_red_black/main/astobj2.c Fri Aug 31 10:37:23 2012
@@ -2963,6 +2963,11 @@
 			/* Check backward link. */
 			prev = AST_DLLIST_PREV(node, links);
 			if (prev) {
+				if (prev == node) {
+					ast_log(LOG_ERROR, "Bucket %d list node's prev pointer points to itself!\n",
+						bucket);
+					return -1;
+				}
 				if (node != AST_DLLIST_NEXT(prev, links)) {
 					ast_log(LOG_ERROR, "Bucket %d list node's prev node does not link back!\n",
 						bucket);
@@ -2977,6 +2982,11 @@
 			/* Check forward link. */
 			next = AST_DLLIST_NEXT(node, links);
 			if (next) {
+				if (next == node) {
+					ast_log(LOG_ERROR, "Bucket %d list node's next pointer points to itself!\n",
+						bucket);
+					return -1;
+				}
 				if (node != AST_DLLIST_PREV(next, links)) {
 					ast_log(LOG_ERROR, "Bucket %d list node's next node does not link back!\n",
 						bucket);
@@ -5003,7 +5013,11 @@
 	if (self->root) {
 		/* Check tree links. */
 		if (self->root->parent) {
-			ast_log(LOG_ERROR, "Tree root is not a root node!\n");
+			if (self->root->parent == self->root) {
+				ast_log(LOG_ERROR, "Tree root parent pointer points to itself!\n");
+			} else {
+				ast_log(LOG_ERROR, "Tree root is not a root node!\n");
+			}
 			return -1;
 		}
 		if (self->root->is_red) {
@@ -5013,13 +5027,25 @@
 		}
 		node = self->root;
 		do {
-			if (node->left && node->left->parent != node) {
-				ast_log(LOG_ERROR, "Tree node's left child does not link back!\n");
-				return -1;
-			}
-			if (node->right && node->right->parent != node) {
-				ast_log(LOG_ERROR, "Tree node's right child does not link back!\n");
-				return -1;
+			if (node->left) {
+				if (node->left == node) {
+					ast_log(LOG_ERROR, "Tree node's left pointer points to itself!\n");
+					return -1;
+				}
+				if (node->left->parent != node) {
+					ast_log(LOG_ERROR, "Tree node's left child does not link back!\n");
+					return -1;
+				}
+			}
+			if (node->right) {
+				if (node->right == node) {
+					ast_log(LOG_ERROR, "Tree node's right pointer points to itself!\n");
+					return -1;
+				}
+				if (node->right->parent != node) {
+					ast_log(LOG_ERROR, "Tree node's right child does not link back!\n");
+					return -1;
+				}
 			}
 
 			/* Check red/black node flags. */




More information about the svn-commits mailing list