msilo: reorganized tests to free db_res and build of extra headers
authorDaniel-Constantin Mierla <miconda@gmail.com>
Sun, 23 Jul 2017 07:42:21 +0000 (09:42 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Sun, 23 Jul 2017 07:42:21 +0000 (09:42 +0200)
src/modules/msilo/msfuncs.c
src/modules/msilo/msilo.c

index 43bc82c..5262a81 100644 (file)
@@ -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++ = ']';
index d231ae7..f62557c 100644 (file)
@@ -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 @@ done:
         * 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;