[sr-dev] git:master:64583809: debugger: Fix coredump when kamailio stopped

smititelu stefan.mititelu at 1and1.ro
Wed Dec 16 12:39:08 CET 2015


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

Author: smititelu <stefan.mititelu at 1and1.ro>
Committer: smititelu <stefan.mititelu at 1and1.ro>
Date: 2015-12-16T13:28:43+02:00

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.

---

Modified: modules/debugger/debugger_api.c
Modified: modules/debugger/debugger_mod.c

---

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

---

diff --git a/modules/debugger/debugger_api.c b/modules/debugger/debugger_api.c
index 107fa09..d0ce44f 100644
--- a/modules/debugger/debugger_api.c
+++ b/modules/debugger/debugger_api.c
@@ -1354,6 +1354,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;
 
@@ -1397,6 +1401,10 @@ int dbg_get_mod_debug_facility(char *mname, int mnlen, int *mfacility)
 	if(_dbg_mod_table==NULL)
 		return -1;
 
+	if (!dbg_cfg) {
+		return -1;
+	}
+
 	if(cfg_get(dbg, dbg_cfg, mod_facility_mode)==0)
 		return -1;
 
diff --git a/modules/debugger/debugger_mod.c b/modules/debugger/debugger_mod.c
index 44c5865..fd1d91b 100644
--- a/modules/debugger/debugger_mod.c
+++ b/modules/debugger/debugger_mod.c
@@ -167,6 +167,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 facility_mode:%d hash_size:%d\n",
 		cfg_get(dbg, dbg_cfg, mod_level_mode),
 		cfg_get(dbg, dbg_cfg, mod_facility_mode),
@@ -231,6 +237,7 @@ static int child_init(int rank)
  */
 static void mod_destroy(void)
 {
+	dbg_cfg = NULL;
 }
 
 /**
@@ -352,19 +359,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;
 
 }
@@ -392,19 +407,27 @@ static int dbg_mod_facility_param(modparam_t type, void *val)
 
 	s.s = (char*)val;
 	s.len = p - s.s;
+
+	if (!dbg_cfg) {
+                return -1;
+	}
+
 	LM_DBG("cfg facility_mode:%d hash_size:%d\n",
 		cfg_get(dbg, dbg_cfg, mod_facility_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_facility(s.s, s.len, &fl)<0)
 	{
 		LM_ERR("cannot store parameter: %s\n", (char*)val);
 		return -1;
 	}
+
 	return 0;
 }
 




More information about the sr-dev mailing list