Browse code

permissions: safety check for trusted hash table

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

(cherry picked from commit f2958e5861a96e40f0aca05d5d5bd7fa14c2089e)

Daniel-Constantin Mierla authored on 17/07/2015 06:59:29
Showing 1 changed files
... ...
@@ -43,9 +43,9 @@
43 43
 
44 44
 #define TABLE_VERSION 5
45 45
 
46
-struct trusted_list ***hash_table;     /* Pointer to current hash table pointer */
47
-struct trusted_list **hash_table_1;   /* Pointer to hash table 1 */
48
-struct trusted_list **hash_table_2;   /* Pointer to hash table 2 */
46
+struct trusted_list ***hash_table = 0;    /* Pointer to current hash table pointer */
47
+struct trusted_list **hash_table_1 = 0;   /* Pointer to hash table 1 */
48
+struct trusted_list **hash_table_2 = 0;   /* Pointer to hash table 2 */
49 49
 
50 50
 
51 51
 static db1_con_t* db_handle = 0;
... ...
@@ -69,16 +69,21 @@ int reload_trusted_table(void)
69 69
 
70 70
 	char *pattern, *tag;
71 71
 
72
-	cols[0] = &source_col;
73
-	cols[1] = &proto_col;
74
-	cols[2] = &from_col;
75
-	cols[3] = &tag_col;
72
+	if (hash_table == 0) {
73
+	    LM_ERR("in-memory hash table not initialized\n");
74
+	    return -1;
75
+	}
76 76
 
77 77
 	if (db_handle == 0) {
78 78
 	    LM_ERR("no connection to database\n");
79 79
 	    return -1;
80 80
 	}
81 81
 
82
+	cols[0] = &source_col;
83
+	cols[1] = &proto_col;
84
+	cols[2] = &from_col;
85
+	cols[3] = &tag_col;
86
+
82 87
 	if (perm_dbf.use_table(db_handle, &trusted_table) < 0) {
83 88
 		LM_ERR("failed to use trusted table\n");
84 89
 		return -1;