<HTML><BODY>Dear All,<br><br>It looks like there is a serious error inside db_mongodb module in the latest versions of Kamailio 4.4.7 and 5.1.2.<br><br>During query operations string fields inside result structure <strong>db1_res_t</strong> could be corrupted because of incorrect usage of bson memory.<br>The issue is located in the function <strong>db_mongodb_convert_bson()</strong> around line 614.<br><br>This issue is reproduced when we need to read more than 150 documents from the database. So that is why this issue still exists.<br><br>Firstly <strong>bson_iter_utf8</strong> function returns pointer to memory which is allocated inside bson memory and which is used multiple times.<br>So the data must be copied into Kamailio memory instead storing that pointer. The pointer becomes invalid after some time.<br><br>Secondly, this pointer must not be freed by the caller of <strong>bson_iter_utf8</strong>. At the current version bson allocated pointer is freed by Kamailio function <strong>pkg_free</strong> like it is was allocated by <strong>pkg_malloc</strong>.<br><br>So I am going to create ticket in the github and propose the fix.<br><br>It looks like nobody uses mongodb with Kamailio in db_mode=1 :)<br><br>Best regards<br>Konstantin<br><br><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div id=""><div class="js-helper js-readmsg-msg"><div><div id="style_15243913030000001012_BODY">----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Sat, 21 Apr 2018 23:37:26 +0300<br>
From: Konstantin Polyakov <<a href="mailto:piligrim_pk@mail.ru">piligrim_pk@mail.ru</a>><br>
To: <a href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a><br>
Subject: [SR-Users] Kamailio doesn't start with db_mongodb and usrloc.<br>
Message-ID: <<a href="mailto:1524343046.238272820@f356.i.mail.ru">1524343046.238272820@f356.i.mail.ru</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
<br>
Hello!<br>
<br>
Similar issue but with different symptoms. <br>
<br>
kamailio 4.4.7 (tried to use db_mongodb module from 5.1.2)<br>
usrloc is configured to use db_mode=1 and db_insert_null=1.<br>
<br>
MongoDB 3.6.3<br>
mongo-c-driver was tested 1.9.2 and 1.9.4.<br>
<br>
location table contains 300 records.<br>
<br>
The issue was not reproduced since February when we started a new feature. Now it is reproduced constantly, but on some machines.<br>
<br>
Logs:<br>
<br>
[0;39;49m[0;39;49m 1(13958) DEBUG: usrloc [udomain.c:313]: dbrow2info(): non-local socket <all.com>...ignoring<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:476]: preload_udomain(): empty username record in table location...skipping<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:256]: dbrow2info(): bad callid<br>
[0;39;49m[0;31;49m 1(13958) ERROR: usrloc [udomain.c:484]: preload_udomain(): skipping record for agent in table location<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:476]: preload_udomain(): empty username record in table location...skipping<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:231]: dbrow2info(): bad contact<br>
[0;39;49m[0;31;49m 1(13958) ERROR: usrloc [udomain.c:484]: preload_udomain(): skipping record for cflags in table location<br>
[0;39;49m[0;39;49m 1(13958) DEBUG: usrloc [udomain.c:313]: dbrow2info(): non-local socket <��keepalive>...ignoring<br>
[0;39;49m[0;35;49m 1(13958) WARNING: usrloc [../../ut.h:717]: shm_str_dup(): shm_str_dup fallback; dup called for src->s == NULL or src->len < 0<br>
[0;39;49m[0;35;49m 1(13958) WARNING: usrloc [../../ut.h:731]: shm_str_dup(): shm_str_dup fallback; skip memcpy for src->s == NULL<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:476]: preload_udomain(): empty username record in table location...skipping<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:231]: dbrow2info(): bad contact<br>
[0;39;49m[0;31;49m 1(13958) ERROR: usrloc [udomain.c:484]: preload_udomain(): skipping record for cseq in table location<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:231]: dbrow2info(): bad contact<br>
[0;39;49m[0;31;49m 1(13958) ERROR: usrloc [udomain.c:484]: preload_udomain(): skipping record for 5.17.xxx in table location<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:231]: dbrow2info(): bad contact<br>
[0;39;49m[0;31;49m 1(13958) ERROR: usrloc [udomain.c:484]: preload_udomain(): skipping record for .17.x in table location<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:476]: preload_udomain(): empty username record in table location...skipping<br>
[0;39;49m[0;39;49m 1(13958) DEBUG: usrloc [udomain.c:313]: dbrow2info(): non-local socket <nce>...ignoring<br>
[0;39;49m[0;35;49m 1(13958) WARNING: usrloc [../../ut.h:717]: shm_str_dup(): shm_str_dup fallback; dup called for src->s == NULL or src->len < 0<br>
[0;39;49m[0;35;49m 1(13958) WARNING: usrloc [../../ut.h:731]: shm_str_dup(): shm_str_dup fallback; skip memcpy for src->s == NULL<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:476]: preload_udomain(): empty username record in table location...skipping<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:476]: preload_udomain(): empty username record in table location...skipping<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:476]: preload_udomain(): empty username record in table location...skipping<br>
[0;39;49m[0;39;49m 1(13958) DEBUG: usrloc [udomain.c:313]: dbrow2info(): non-local socket <c-89-5ada654b-35a2-42>...ignoring<br>
[0;39;49m[0;39;49m 1(13958) DEBUG: usrloc [udomain.c:313]: dbrow2info(): non-local socket <>...ignoring<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: usrloc [udomain.c:231]: dbrow2info(): bad contact<br>
[0;39;49m[0;31;49m 1(13958) ERROR: usrloc [udomain.c:484]: preload_udomain(): skipping record for 38.146:5360 in table location<br>
[0;39;49m[0;39;49m 1(13958) DEBUG: usrloc [udomain.c:313]: dbrow2info(): non-local socket <ified>...ignoring<br>
[0;39;49m[0;31;49m 1(13958) ERROR: usrloc [ucontact.c:94]: new_ucontact(): no ruid for aor: lQ.com@5.17.60@8/Ղusername<br>
[0;39;49m[0;31;49m 1(13958) ERROR: usrloc [urecord.c:149]: mem_insert_ucontact(): failed to create new contact<br>
[0;39;49m[0;31;49m 1(13958) ERROR: usrloc [udomain.c:517]: preload_udomain(): inserting contact failed<br>
[0;39;49m[0;31;49m 1(13958) ERROR: usrloc [ul_mod.c:457]: child_init(): child(1): failed to preload domain 'location'<br>
[0;39;49m[0;31;49m 1(13958) ERROR: <core> [sr_module.c:923]: init_mod_child(): Error while initializing module usrloc (/usr/ecsp/lib64/kamailio/modules/usrloc.so)<br>
[0;39;49m[0;31;49m 1(13958) ERROR: <core> [pt.c:329]: fork_process(): init_child failed for process 1, pid 13958, "udp receiver child=0 sock=5.17.138.137:5060 (5.17.138.137:5060)"<br>
[0;39;49m[0;33;49m 1(13958) CRITICAL: <core> [main.c:1615]: main_loop(): Cannot fork<br>
[0;39;49m[1;31;49m 0(13956) ALERT: <core> [main.c:740]: handle_sigs(): child process 13958 exited normally, status=255<br>
[0;39;49m[0;36;49m 0(13956) INFO: <core> [main.c:768]: handle_sigs(): terminating due to SIGCHLD<br>
[0;39;49m[0;39;49m 0(13956) DEBUG: <core> [main.c:770]: handle_sigs(): terminating due to SIGCHLD<br>
<br>
<br>
Could you please help us to resolve the issue?<br>
Thank you in advance.<br>
Best regards<br>
Konstantin<br> <br></div></div></div></div></blockquote><br><style type="text/css"></style></BODY></HTML>