[sr-dev] git:4.2:b399bb34: dtrie: Set child to NULL when run out of SHM
Stefan Mititelu
stefan.mititelu at 1and1.ro
Tue Aug 11 14:49:42 CEST 2015
Module: kamailio
Branch: 4.2
Commit: b399bb34cebdb1002d27bb0cf554f2d2e683c40d
URL: https://github.com/kamailio/kamailio/commit/b399bb34cebdb1002d27bb0cf554f2d2e683c40d
Author: Stefan Mititelu <stefan.mititelu at 1and1.ro>
Committer: Stefan Mititelu <stefan.mititelu at 1and1.ro>
Date: 2015-08-11T15:49:07+03:00
dtrie: Set child to NULL when run out of SHM
The stop condition in dtrie_delete is node==NULL. Suppose the case when there
is no SHM memory left when trying to dtrie_insert(). The memory gets freed
by shm_free() but the pointer still points to it. This leads to segfault when
dtrie_delete tries to access that memory zone, in the given case. GDB says:
"Cannot access memory at address 0x1130000001d"
(cherry picked from commit 60ffee9cf54ff362026497036935746c9dbe62e5)
---
Modified: lib/trie/dtrie.c
---
Diff: https://github.com/kamailio/kamailio/commit/b399bb34cebdb1002d27bb0cf554f2d2e683c40d.diff
Patch: https://github.com/kamailio/kamailio/commit/b399bb34cebdb1002d27bb0cf554f2d2e683c40d.patch
---
diff --git a/lib/trie/dtrie.c b/lib/trie/dtrie.c
index a57f85d..2883829 100644
--- a/lib/trie/dtrie.c
+++ b/lib/trie/dtrie.c
@@ -152,6 +152,7 @@ int dtrie_insert(struct dtrie_node_t *root, const char *number, const unsigned i
if(node->child[digit]->child == NULL){
SHM_MEM_ERROR;
shm_free(node->child[digit]);
+ node->child[digit] = NULL;
return -1;
}
LM_DBG("allocate %lu bytes for %d root children pointer at %p\n",
More information about the sr-dev
mailing list