Explorar o código

debugger: Fix coredump when kamailio stopped

Upon kamailio stop, 'dbg_cfg' pointed to invalid memory zone(not NULL).
Reset the pointer to NULL upon module_destroy() and do the NULL checks.

Reported by foucse in issue #446.

(cherry picked from commit 64583809c677384e2fcd54a5ba7f921b3ea59c51)
smititelu %!s(int64=9) %!d(string=hai) anos
pai
achega
43d01aab8b
Modificáronse 2 ficheiros con 19 adicións e 1 borrados
  1. 4 0
      modules/debugger/debugger_api.c
  2. 15 1
      modules/debugger/debugger_mod.c

+ 4 - 0
modules/debugger/debugger_api.c

@@ -1221,6 +1221,10 @@ int dbg_get_mod_debug_level(char *mname, int mnlen, int *mlevel)
 	if(_dbg_mod_table==NULL)
 		return -1;
 
+	if (!dbg_cfg) {
+		return -1;
+	}
+
 	if(cfg_get(dbg, dbg_cfg, mod_level_mode)==0)
 		return -1;
 

+ 15 - 1
modules/debugger/debugger_mod.c

@@ -141,6 +141,12 @@ static int mod_init(void)
 		LM_ERR("Fail to declare the configuration\n");
 		return -1;
 	}
+
+	/* anyhow, should fail before */
+	if (!dbg_cfg) {
+                return -1;
+	}
+
 	LM_DBG("cfg level_mode:%d hash_size:%d\n",
 		cfg_get(dbg, dbg_cfg, mod_level_mode),
 		cfg_get(dbg, dbg_cfg, mod_hash_size));
@@ -190,6 +196,7 @@ static int child_init(int rank)
  */
 static void mod_destroy(void)
 {
+	dbg_cfg = NULL;
 }
 
 /**
@@ -311,20 +318,27 @@ static int dbg_mod_level_param(modparam_t type, void *val)
 	}
 	s.s = (char*)val;
 	s.len = p - s.s;
+
+	if (!dbg_cfg) {
+                return -1;
+	}
+
 	LM_DBG("cfg level_mode:%d hash_size:%d\n",
 		cfg_get(dbg, dbg_cfg, mod_level_mode),
 		cfg_get(dbg, dbg_cfg, mod_hash_size));
+
 	if(dbg_init_mod_levels(cfg_get(dbg, dbg_cfg, mod_hash_size))<0)
 	{
 		LM_ERR("failed to init per module log level\n");
 		return -1;
 	}
+
 	if(dbg_set_mod_debug_level(s.s, s.len, &l)<0)
 	{
 		LM_ERR("cannot store parameter: %s\n", (char*)val);
 		return -1;
 	}
+
 	return 0;
 
 }
-