pv: use safer macros for temporarily making zero-ending strings
authorDaniel-Constantin Mierla <miconda@gmail.com>
Tue, 28 Apr 2020 07:42:13 +0000 (09:42 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Tue, 28 Apr 2020 07:42:13 +0000 (09:42 +0200)
src/modules/pv/pv_branch.c
src/modules/pv/pv_core.c
src/modules/pv/pv_select.c

index 8100046..51fb302 100644 (file)
@@ -13,8 +13,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -241,16 +241,15 @@ int pv_set_branchx_helper(sip_msg_t *msg, pv_param_t *param,
                                br->force_send_socket = NULL;
                                break;
                        }
-                       backup = val->rs.s[val->rs.len];
-                       val->rs.s[val->rs.len] = '\0';
+                       STR_VTOZ(val->rs.s[val->rs.len], backup);
                        if (parse_phostport(val->rs.s, &host.s, &host.len, &port,
                                                &proto) < 0)
                        {
                                LM_ERR("invalid socket specification\n");
-                               val->rs.s[val->rs.len] = backup;
+                               STR_ZTOV(val->rs.s[val->rs.len], backup);
                                return -1;
                        }
-                       val->rs.s[val->rs.len] = backup;
+                       STR_ZTOV(val->rs.s[val->rs.len], backup);
                        si = grep_sock_info(&host, (unsigned short)port,
                                        (unsigned short)proto);
                        if (si!=NULL)
index ad5db64..5a83a89 100644 (file)
@@ -2424,17 +2424,16 @@ int pv_set_ruri(struct sip_msg* msg, pv_param_t *param,
        memset(&act, 0, sizeof(act));
        act.val[0].type = STRING_ST;
        act.val[0].u.string = val->rs.s;
-       backup = val->rs.s[val->rs.len];
-       val->rs.s[val->rs.len] = '\0';
+       STR_VTOZ(val->rs.s[val->rs.len], backup);
        act.type = SET_URI_T;
        init_run_actions_ctx(&h);
        if (do_action(&h, &act, msg)<0)
        {
                LM_ERR("do action failed\n");
-               val->rs.s[val->rs.len] = backup;
+               STR_ZTOV(val->rs.s[val->rs.len], backup);
                goto error;
        }
-       val->rs.s[val->rs.len] = backup;
+       STR_ZTOV(val->rs.s[val->rs.len], backup);
 
        return 0;
 error:
@@ -2479,17 +2478,16 @@ int pv_set_ruri_user(struct sip_msg* msg, pv_param_t *param,
        memset(&act, 0, sizeof(act));
        act.val[0].type = STRING_ST;
        act.val[0].u.string = val->rs.s;
-       backup = val->rs.s[val->rs.len];
-       val->rs.s[val->rs.len] = '\0';
+       STR_VTOZ(val->rs.s[val->rs.len], backup);
        act.type = SET_USER_T;
        init_run_actions_ctx(&h);
        if (do_action(&h, &act, msg)<0)
        {
                LM_ERR("do action failed\n");
-               val->rs.s[val->rs.len] = backup;
+               STR_ZTOV(val->rs.s[val->rs.len], backup);
                goto error;
        }
-       val->rs.s[val->rs.len] = backup;
+       STR_ZTOV(val->rs.s[val->rs.len], backup);
 
        return 0;
 error:
@@ -2518,17 +2516,16 @@ int pv_set_ruri_host(struct sip_msg* msg, pv_param_t *param,
        memset(&act, 0, sizeof(act));
        act.val[0].type = STRING_ST;
        act.val[0].u.string = val->rs.s;
-       backup = val->rs.s[val->rs.len];
-       val->rs.s[val->rs.len] = '\0';
+       STR_VTOZ(val->rs.s[val->rs.len], backup);
        act.type = SET_HOST_T;
        init_run_actions_ctx(&h);
        if (do_action(&h, &act, msg)<0)
        {
                LM_ERR("do action failed\n");
-               val->rs.s[val->rs.len] = backup;
+               STR_ZTOV(val->rs.s[val->rs.len], backup);
                goto error;
        }
-       val->rs.s[val->rs.len] = backup;
+       STR_ZTOV(val->rs.s[val->rs.len], backup);
 
        return 0;
 error:
@@ -2572,21 +2569,16 @@ int pv_set_ruri_port(struct sip_msg* msg, pv_param_t *param,
        memset(&act, 0, sizeof(act));
        act.val[0].type = STRING_ST;
        act.val[0].u.string = val->rs.s;
-       backup = val->rs.s[val->rs.len];
-       if(backup != '\0') {
-               val->rs.s[val->rs.len] = '\0';
-       }
+       STR_VTOZ(val->rs.s[val->rs.len], backup);
        act.type = SET_PORT_T;
        init_run_actions_ctx(&h);
        if (do_action(&h, &act, msg)<0)
        {
                LM_ERR("do action failed\n");
-               val->rs.s[val->rs.len] = backup;
+               STR_ZTOV(val->rs.s[val->rs.len], backup);
                goto error;
        }
-       if(backup != '\0') {
-               val->rs.s[val->rs.len] = backup;
-       }
+       STR_ZTOV(val->rs.s[val->rs.len], backup);
 
        return 0;
 error:
@@ -2646,15 +2638,14 @@ int pv_set_force_sock(struct sip_msg* msg, pv_param_t *param,
                goto error;
        }
 
-       backup = val->rs.s[val->rs.len];
-       val->rs.s[val->rs.len] = '\0';
+       STR_VTOZ(val->rs.s[val->rs.len], backup);
        if (parse_phostport(val->rs.s, &host.s, &host.len, &port, &proto) < 0)
        {
                LM_ERR("invalid socket specification\n");
-               val->rs.s[val->rs.len] = backup;
+               STR_ZTOV(val->rs.s[val->rs.len], backup);
                goto error;
        }
-       val->rs.s[val->rs.len] = backup;
+       STR_ZTOV(val->rs.s[val->rs.len], backup);
        LM_DBG("trying to set send-socket to [%.*s]\n", val->rs.len, val->rs.s);
        si = grep_sock_info(&host, (unsigned short)port, (unsigned short)proto);
        if (si!=NULL)
index d558461..73a57c9 100644 (file)
@@ -13,8 +13,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -34,17 +34,16 @@ int pv_parse_select_name(pv_spec_p sp, str *in)
        if (in == NULL || in->s == NULL || sp == NULL)
                return -1;
 
-       c = in->s[in->len];
-       in->s[in->len] = '\0';
+       STR_VTOZ(in->s[in->len], c);
        p = in->s;
        if(parse_select(&p, &sel)<0)
        {
                LM_ERR("invalid select name [%.*s]\n",
                                in->len, in->s);
-               in->s[in->len] = c;
+               STR_ZTOV(in->s[in->len], c);
                return -1;
        }
-       in->s[in->len] = c;
+       STR_ZTOV(in->s[in->len], c);
        sp->pvp.pvn.u.dname = (void*)sel;
        sp->pvp.pvn.type = PV_NAME_OTHER;
        return 0;