Module: kamailio
Branch: master
Commit: f2958e5861a96e40f0aca05d5d5bd7fa14c2089e
URL: 
https://github.com/kamailio/kamailio/commit/f2958e5861a96e40f0aca05d5d5bd7fa14c2089e

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2015-07-17T09:04:28+02:00

permissions: safety check for trusted hash table

- avoid crash if a db reload is issued in db-only mode
- reported Emmanuel Schmidbauer, GH #228

---

Modified: modules/permissions/trusted.c

---

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

---

diff --git a/modules/permissions/trusted.c b/modules/permissions/trusted.c
index 8da51ff..67e70a1 100644
--- a/modules/permissions/trusted.c
+++ b/modules/permissions/trusted.c
@@ -43,9 +43,9 @@
 
 #define TABLE_VERSION 6
 
-struct trusted_list ***hash_table;     /* Pointer to current hash table 
pointer */
-struct trusted_list **hash_table_1;   /* Pointer to hash table 1 */
-struct trusted_list **hash_table_2;   /* Pointer to hash table 2 */
+struct trusted_list ***hash_table = 0;    /* Pointer to current hash table 
pointer */
+struct trusted_list **hash_table_1 = 0;   /* Pointer to hash table 1 */
+struct trusted_list **hash_table_2 = 0;   /* Pointer to hash table 2 */
 
 
 static db1_con_t* db_handle = 0;
@@ -70,6 +70,16 @@ int reload_trusted_table(void)
 
        char *pattern, *ruri_pattern, *tag;
 
+       if (hash_table == 0) {
+           LM_ERR("in-memory hash table not initialized\n");
+           return -1;
+       }
+
+       if (db_handle == 0) {
+           LM_ERR("no connection to database\n");
+           return -1;
+       }
+
        cols[0] = &source_col;
        cols[1] = &proto_col;
        cols[2] = &from_col;
@@ -77,11 +87,6 @@ int reload_trusted_table(void)
        cols[4] = &tag_col;
        cols[5] = &priority_col;
 
-       if (db_handle == 0) {
-           LM_ERR("no connection to database\n");
-           return -1;
-       }
-
        if (perm_dbf.use_table(db_handle, &trusted_table) < 0) {
                LM_ERR("failed to use trusted table\n");
                return -1;


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to