Module: kamailio
Branch: 4.1
Commit: 804b7f19dc1b95f9226711125d0239574f0aa0a9
URL:
https://github.com/kamailio/kamailio/commit/804b7f19dc1b95f9226711125d02395…
Author: Stefan Mititelu <stefan.mititelu(a)1and1.ro>
Committer: Stefan Mititelu <stefan.mititelu(a)1and1.ro>
Date: 2016-01-22T16:50:57+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/804b7f19dc1b95f9226711125d02395…
Patch:
https://github.com/kamailio/kamailio/commit/804b7f19dc1b95f9226711125d02395…
---
diff --git a/lib/trie/dtrie.c b/lib/trie/dtrie.c
index 783f6e7..abdd589 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;