[sr-dev] git:5.1:f0fbe297: db_mongodb: clone bson UTF8 value into DB val structure

Daniel-Constantin Mierla miconda at gmail.com
Wed Apr 25 14:59:21 CEST 2018


Module: kamailio
Branch: 5.1
Commit: f0fbe297a47c658b63623b2c5912cdf379b3f7fd
URL: https://github.com/kamailio/kamailio/commit/f0fbe297a47c658b63623b2c5912cdf379b3f7fd

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-04-25T14:52:45+02:00

db_mongodb: clone bson UTF8 value into DB val structure

- the bson iterator invalidates or reuses the memory after several interations
- initial patch by Konstantin Poliakov <k.polyakov at mightycall.com>, GH #1508

(cherry picked from commit 1ef70d68599db092fa71b9b8b7cd3fdcd54f8a99)

---

Modified: src/modules/db_mongodb/mongodb_dbase.c

---

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

---

diff --git a/src/modules/db_mongodb/mongodb_dbase.c b/src/modules/db_mongodb/mongodb_dbase.c
index 72d6647689..4b75c0d3a1 100644
--- a/src/modules/db_mongodb/mongodb_dbase.c
+++ b/src/modules/db_mongodb/mongodb_dbase.c
@@ -630,7 +630,13 @@ static int db_mongodb_convert_bson(const db1_con_t* _h, db1_res_t* _r,
 				break;
 
 			case BSON_TYPE_UTF8:
-				VAL_STRING(dval) = (char*)bson_iter_utf8 (piter, &i32tmp);
+				{
+					char* rstring = (char*)bson_iter_utf8 (piter, &i32tmp);
+					if(db_str2val(DB1_STRING, dval, rstring, i32tmp, 1)<0) {
+						LM_ERR("failed to convert utf8 value\n");
+						return -5;
+					}
+				}
 				break;
 
 			case BSON_TYPE_OID:




More information about the sr-dev mailing list