[sr-dev] git:4.2:f5f29ee2: dtrie: sanity checks

Stefan Mititelu stefan.mititelu at 1and1.ro
Fri Jan 22 15:52:55 CET 2016


Module: kamailio
Branch: 4.2
Commit: f5f29ee2e89f1b0662785db0fb09ec34364ed9d7
URL: https://github.com/kamailio/kamailio/commit/f5f29ee2e89f1b0662785db0fb09ec34364ed9d7

Author: Stefan Mititelu <stefan.mititelu at 1and1.ro>
Committer: Stefan Mititelu <stefan.mititelu at 1and1.ro>
Date: 2016-01-22T16:52:34+02:00

dtrie: sanity checks

Segfaults reported by Igor, on sr-Users mailing list.

(cherry picked from commit 825b4fabb9bb4b2cf58dc1205423b8ce5d5e08cc)

---

Modified: lib/trie/dtrie.c

---

Diff:  https://github.com/kamailio/kamailio/commit/f5f29ee2e89f1b0662785db0fb09ec34364ed9d7.diff
Patch: https://github.com/kamailio/kamailio/commit/f5f29ee2e89f1b0662785db0fb09ec34364ed9d7.patch

---

diff --git a/lib/trie/dtrie.c b/lib/trie/dtrie.c
index 2883829..f0b2655 100644
--- a/lib/trie/dtrie.c
+++ b/lib/trie/dtrie.c
@@ -76,7 +76,9 @@ void dtrie_delete(struct dtrie_node_t *root, struct dtrie_node_t *node,
 		dt_delete_func_t delete_payload, const unsigned int branches)
 {
 	unsigned int i;
-	if (node==NULL) return;
+
+	if (node == NULL) return;
+	if (root == NULL) return;
 
 	for (i=0; i<branches; i++) {
 		dtrie_delete(root, node->child[i], delete_payload, branches);
@@ -123,6 +125,10 @@ int dtrie_insert(struct dtrie_node_t *root, const char *number, const unsigned i
 	struct dtrie_node_t *node = root;
 	unsigned char digit, i=0;
 
+	if (node == NULL) return -1;
+	if (root == NULL) return -1;
+	if (number == NULL) return -1;
+
 	while (i<numberlen) {
 		if (branches==10) {
 			digit = number[i] - '0';
@@ -202,6 +208,8 @@ unsigned int dtrie_leaves(const struct dtrie_node_t *root, const unsigned int br
 {
 	unsigned int i, sum = 0, leaf = 1;
 
+	if (root == NULL) return 0;
+
 	for (i=0; i<branches; i++) {
 		if (root->child[i]) {
 			sum += dtrie_leaves(root->child[i], branches);
@@ -220,6 +228,10 @@ void **dtrie_longest_match(struct dtrie_node_t *root, const char *number,
 	unsigned char digit, i = 0;
 	void **ret = NULL;
 
+	if (node == NULL) return NULL;
+	if (root == NULL) return NULL;
+	if (number == NULL) return NULL;
+
 	if (nmatchptr) *nmatchptr=-1;
 	if (node->data != NULL) {
 		if (nmatchptr) *nmatchptr=0;




More information about the sr-dev mailing list