[sr-dev] git:master:dd0c6fb5: msilo: reorganized tests to free db_res and build of extra headers

Daniel-Constantin Mierla miconda at gmail.com
Mon Jul 24 08:27:47 CEST 2017


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-07-23T09:42:21+02:00

msilo: reorganized tests to free db_res and build of extra headers

---

Modified: src/modules/msilo/msfuncs.c
Modified: src/modules/msilo/msilo.c

---

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

---

diff --git a/src/modules/msilo/msfuncs.c b/src/modules/msilo/msfuncs.c
index 43bc82ce60..5262a81159 100644
--- a/src/modules/msilo/msfuncs.c
+++ b/src/modules/msilo/msfuncs.c
@@ -211,30 +211,30 @@ int m_build_headers(str *buf, str ctype, str contact, time_t date, str extra)
 	if(date > 0)
 	{
 		lenDate = timetToSipDateStr(date,strDate,48);
-		strncpy(p, strDate, lenDate);
+		memcpy(p, strDate, lenDate);
 		p += lenDate;
 	}
 	if(ctype.len > 0)
 	{
-		strncpy(p, "Content-Type: ", 14);
+		memcpy(p, "Content-Type: ", 14);
 		p += 14;
-		strncpy(p, ctype.s, ctype.len);
+		memcpy(p, ctype.s, ctype.len);
 		p += ctype.len;
-		strncpy(p, CRLF, CRLF_LEN);
+		memcpy(p, CRLF, CRLF_LEN);
 		p += CRLF_LEN;
 	
 	}
 	if(contact.len > 0 && ms_add_contact)
 	{
-		strncpy(p, CONTACT_PREFIX, CONTACT_PREFIX_LEN);
+		memcpy(p, CONTACT_PREFIX, CONTACT_PREFIX_LEN);
 		p += CONTACT_PREFIX_LEN;
-		strncpy(p, contact.s, contact.len);
+		memcpy(p, contact.s, contact.len);
 		p += contact.len;
-		strncpy(p, CONTACT_SUFFIX, CONTACT_SUFFIX_LEN);
+		memcpy(p, CONTACT_SUFFIX, CONTACT_SUFFIX_LEN);
 		p += CONTACT_SUFFIX_LEN;
 	}
 	if (extra.len > 0) {
-	    strncpy(p, extra.s, extra.len);
+	    memcpy(p, extra.s, extra.len);
 	    p += extra.len;
 	}
 	buf->len = p - buf->s;	
@@ -263,18 +263,18 @@ int m_build_body(str *body, time_t date, str msg, time_t sdate)
 	{
 		if(sdate!=0)
 		{
-			strncpy(p, "[Reminder message - ", 20);
+			memcpy(p, "[Reminder message - ", 20);
 			p += 20;
 		
-			strncpy(p, ctime(&sdate), 24);
+			memcpy(p, ctime(&sdate), 24);
 			p += 24;
 
 			*p++ = ']';
 		} else {
-			strncpy(p, "[Offline message - ", 19);
+			memcpy(p, "[Offline message - ", 19);
 			p += 19;
 	
-			strncpy(p, ctime(&date), 24);
+			memcpy(p, ctime(&date), 24);
 			p += 24;
 
 			*p++ = ']';
diff --git a/src/modules/msilo/msilo.c b/src/modules/msilo/msilo.c
index d231ae7e6e..f62557ce2a 100644
--- a/src/modules/msilo/msilo.c
+++ b/src/modules/msilo/msilo.c
@@ -1039,8 +1039,11 @@ static int m_dump(struct sip_msg* msg, str* owner_s)
 	}
 
 	if (msilo_dbf.query(db_con,db_keys,db_ops,db_vals,db_cols,db_no_keys,
-			    db_no_cols, ob_key, &db_res) < 0) {
+			    db_no_cols, ob_key, &db_res) < 0 || db_res==NULL) {
 	    LM_ERR("failed to query database\n");
+		if (db_res!=NULL && msilo_dbf.free_result(db_con, db_res) < 0) {
+			LM_ERR("failed to free the query result\n");
+		}
 	    goto error;
 	}
 
@@ -1071,13 +1074,13 @@ static int m_dump(struct sip_msg* msg, str* owner_s)
 			(time_t)RES_ROWS(db_res)[i].values[5/*inc time*/].val.int_val;
 		
 		if (ms_extra_hdrs != NULL) {
-		    if (fixup_get_svalue(msg, (gparam_p)*ms_extra_hdrs_sp,
-					 &extra_hdrs_str) != 0) {
-			if (msilo_dbf.free_result(db_con, db_res) < 0)
-				LM_ERR("failed to free the query result\n");
-			LM_ERR("unable to get extra_hdrs value\n");
-			goto error;
-		    }
+			if(fixup_get_svalue(msg, (gparam_p)*ms_extra_hdrs_sp,
+					&extra_hdrs_str) != 0) {
+				if(msilo_dbf.free_result(db_con, db_res) < 0)
+					LM_ERR("failed to free the query result\n");
+				LM_ERR("unable to get extra_hdrs value\n");
+				goto error;
+			}
 		} else {
 		    extra_hdrs_str.len = 0;
 		}
@@ -1153,7 +1156,7 @@ static int m_dump(struct sip_msg* msg, str* owner_s)
 	 * Free the result because we don't need it
 	 * anymore
 	 */
-	if ((db_res !=NULL) && msilo_dbf.free_result(db_con, db_res) < 0)
+	if (msilo_dbf.free_result(db_con, db_res) < 0)
 		LM_ERR("failed to free result of query\n");
 
 	return 1;




More information about the sr-dev mailing list