[sr-dev] git:5.2:b61fc371: imc: fix a chat room related crash and DB reload problems (GH #1855)

Henning Westerholt hw at kamailio.org
Sun Feb 17 21:05:15 CET 2019


Module: kamailio
Branch: 5.2
Commit: b61fc371f8057d3a4a688507c9e43d89719cedc4
URL: https://github.com/kamailio/kamailio/commit/b61fc371f8057d3a4a688507c9e43d89719cedc4

Author: Jan Janak <jan at janakj.org>
Committer: Henning Westerholt <hw at kamailio.org>
Date: 2019-02-17T21:05:04+01:00

imc: fix a chat room related crash and DB reload problems (GH #1855)

- Avoid crash in case a chat room has no members.
  The imc module may encounter chat rooms that, for one reason or another,
  have no members. In that case, we cannot use the URI of the first member
  as the owner URI. This happens, for example, when the destroy function
  fails to save chat room members into the database.
- When storing data in database, use replace instead of insert.
  The insert statement would fail with an index violation if the
  database already contains a matching record. That would happen, for
  example, if some of the records being saved in mod_destroy were
  re-loaded from the database on server start.

(cherry picked from commit 669bb9a07773399a1305ee6b977529b39f0932aa)

---

Modified: src/modules/imc/imc.c

---

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

---

diff --git a/src/modules/imc/imc.c b/src/modules/imc/imc.c
index e670ea7e0d..e9c88a294a 100644
--- a/src/modules/imc/imc.c
+++ b/src/modules/imc/imc.c
@@ -674,9 +674,9 @@ static void destroy(void)
 				return;
 			}
 
-			if(imc_dbf.insert(imc_db, rq_cols, rq_vals, 3)<0)
+			if(imc_dbf.replace(imc_db, rq_cols, rq_vals, 3, 2, 0)<0)
 			{
-				LM_ERR("failed to insert into table imc_rooms\n");
+				LM_ERR("failed to replace into table imc_rooms\n");
 				return;
 			}
 			LM_DBG("room %d %.*s\n", i, irp->name.len, irp->name.s);
@@ -694,9 +694,9 @@ static void destroy(void)
 					return;
 				}
 
-				if(imc_dbf.insert(imc_db, mq_cols, mq_vals, 4)<0)
+				if(imc_dbf.replace(imc_db, mq_cols, mq_vals, 4, 2, 0)<0)
 				{
-					LM_ERR("failed to insert  into table imc_rooms\n");
+					LM_ERR("failed to replace  into table imc_rooms\n");
 					return;
 				}
 				member = member->next;
@@ -716,6 +716,7 @@ static void  imc_rpc_list_rooms(rpc_t* rpc, void* ctx)
 	int i;
 	imc_room_p irp = NULL;
 	void *vh;
+	static str unknown = STR_STATIC_INIT("");
 
 	for(i=0; i<imc_hash_size; i++)
 	{
@@ -730,7 +731,7 @@ static void  imc_rpc_list_rooms(rpc_t* rpc, void* ctx)
 			rpc->struct_add(vh, "SdS",
 					"room", &irp->uri,
 					"members", irp->nr_of_members,
-					"owner", &irp->members->uri);
+					"owner", (irp->nr_of_members > 0) ? &irp->members->uri : &unknown);
 
 			irp = irp->next;
 		}




More information about the sr-dev mailing list