Browse code

pv: use safer macros for temporarily making zero-ending strings

Daniel-Constantin Mierla authored on 28/04/2020 07:42:13
Showing 3 changed files
... ...
@@ -13,8 +13,8 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  */
20 20
 
... ...
@@ -241,16 +241,15 @@ int pv_set_branchx_helper(sip_msg_t *msg, pv_param_t *param,
241 241
 				br->force_send_socket = NULL;
242 242
 				break;
243 243
 			}
244
-			backup = val->rs.s[val->rs.len];
245
-			val->rs.s[val->rs.len] = '\0';
244
+			STR_VTOZ(val->rs.s[val->rs.len], backup);
246 245
 			if (parse_phostport(val->rs.s, &host.s, &host.len, &port,
247 246
 						&proto) < 0)
248 247
 			{
249 248
 				LM_ERR("invalid socket specification\n");
250
-				val->rs.s[val->rs.len] = backup;
249
+				STR_ZTOV(val->rs.s[val->rs.len], backup);
251 250
 				return -1;
252 251
 			}
253
-			val->rs.s[val->rs.len] = backup;
252
+			STR_ZTOV(val->rs.s[val->rs.len], backup);
254 253
 			si = grep_sock_info(&host, (unsigned short)port,
255 254
 					(unsigned short)proto);
256 255
 			if (si!=NULL)
... ...
@@ -2424,17 +2424,16 @@ int pv_set_ruri(struct sip_msg* msg, pv_param_t *param,
2424 2424
 	memset(&act, 0, sizeof(act));
2425 2425
 	act.val[0].type = STRING_ST;
2426 2426
 	act.val[0].u.string = val->rs.s;
2427
-	backup = val->rs.s[val->rs.len];
2428
-	val->rs.s[val->rs.len] = '\0';
2427
+	STR_VTOZ(val->rs.s[val->rs.len], backup);
2429 2428
 	act.type = SET_URI_T;
2430 2429
 	init_run_actions_ctx(&h);
2431 2430
 	if (do_action(&h, &act, msg)<0)
2432 2431
 	{
2433 2432
 		LM_ERR("do action failed\n");
2434
-		val->rs.s[val->rs.len] = backup;
2433
+		STR_ZTOV(val->rs.s[val->rs.len], backup);
2435 2434
 		goto error;
2436 2435
 	}
2437
-	val->rs.s[val->rs.len] = backup;
2436
+	STR_ZTOV(val->rs.s[val->rs.len], backup);
2438 2437
 
2439 2438
 	return 0;
2440 2439
 error:
... ...
@@ -2479,17 +2478,16 @@ int pv_set_ruri_user(struct sip_msg* msg, pv_param_t *param,
2479 2478
 	memset(&act, 0, sizeof(act));
2480 2479
 	act.val[0].type = STRING_ST;
2481 2480
 	act.val[0].u.string = val->rs.s;
2482
-	backup = val->rs.s[val->rs.len];
2483
-	val->rs.s[val->rs.len] = '\0';
2481
+	STR_VTOZ(val->rs.s[val->rs.len], backup);
2484 2482
 	act.type = SET_USER_T;
2485 2483
 	init_run_actions_ctx(&h);
2486 2484
 	if (do_action(&h, &act, msg)<0)
2487 2485
 	{
2488 2486
 		LM_ERR("do action failed\n");
2489
-		val->rs.s[val->rs.len] = backup;
2487
+		STR_ZTOV(val->rs.s[val->rs.len], backup);
2490 2488
 		goto error;
2491 2489
 	}
2492
-	val->rs.s[val->rs.len] = backup;
2490
+	STR_ZTOV(val->rs.s[val->rs.len], backup);
2493 2491
 
2494 2492
 	return 0;
2495 2493
 error:
... ...
@@ -2518,17 +2516,16 @@ int pv_set_ruri_host(struct sip_msg* msg, pv_param_t *param,
2518 2516
 	memset(&act, 0, sizeof(act));
2519 2517
 	act.val[0].type = STRING_ST;
2520 2518
 	act.val[0].u.string = val->rs.s;
2521
-	backup = val->rs.s[val->rs.len];
2522
-	val->rs.s[val->rs.len] = '\0';
2519
+	STR_VTOZ(val->rs.s[val->rs.len], backup);
2523 2520
 	act.type = SET_HOST_T;
2524 2521
 	init_run_actions_ctx(&h);
2525 2522
 	if (do_action(&h, &act, msg)<0)
2526 2523
 	{
2527 2524
 		LM_ERR("do action failed\n");
2528
-		val->rs.s[val->rs.len] = backup;
2525
+		STR_ZTOV(val->rs.s[val->rs.len], backup);
2529 2526
 		goto error;
2530 2527
 	}
2531
-	val->rs.s[val->rs.len] = backup;
2528
+	STR_ZTOV(val->rs.s[val->rs.len], backup);
2532 2529
 
2533 2530
 	return 0;
2534 2531
 error:
... ...
@@ -2572,21 +2569,16 @@ int pv_set_ruri_port(struct sip_msg* msg, pv_param_t *param,
2572 2569
 	memset(&act, 0, sizeof(act));
2573 2570
 	act.val[0].type = STRING_ST;
2574 2571
 	act.val[0].u.string = val->rs.s;
2575
-	backup = val->rs.s[val->rs.len];
2576
-	if(backup != '\0') {
2577
-		val->rs.s[val->rs.len] = '\0';
2578
-	}
2572
+	STR_VTOZ(val->rs.s[val->rs.len], backup);
2579 2573
 	act.type = SET_PORT_T;
2580 2574
 	init_run_actions_ctx(&h);
2581 2575
 	if (do_action(&h, &act, msg)<0)
2582 2576
 	{
2583 2577
 		LM_ERR("do action failed\n");
2584
-		val->rs.s[val->rs.len] = backup;
2578
+		STR_ZTOV(val->rs.s[val->rs.len], backup);
2585 2579
 		goto error;
2586 2580
 	}
2587
-	if(backup != '\0') {
2588
-		val->rs.s[val->rs.len] = backup;
2589
-	}
2581
+	STR_ZTOV(val->rs.s[val->rs.len], backup);
2590 2582
 
2591 2583
 	return 0;
2592 2584
 error:
... ...
@@ -2646,15 +2638,14 @@ int pv_set_force_sock(struct sip_msg* msg, pv_param_t *param,
2646 2638
 		goto error;
2647 2639
 	}
2648 2640
 
2649
-	backup = val->rs.s[val->rs.len];
2650
-	val->rs.s[val->rs.len] = '\0';
2641
+	STR_VTOZ(val->rs.s[val->rs.len], backup);
2651 2642
 	if (parse_phostport(val->rs.s, &host.s, &host.len, &port, &proto) < 0)
2652 2643
 	{
2653 2644
 		LM_ERR("invalid socket specification\n");
2654
-		val->rs.s[val->rs.len] = backup;
2645
+		STR_ZTOV(val->rs.s[val->rs.len], backup);
2655 2646
 		goto error;
2656 2647
 	}
2657
-	val->rs.s[val->rs.len] = backup;
2648
+	STR_ZTOV(val->rs.s[val->rs.len], backup);
2658 2649
 	LM_DBG("trying to set send-socket to [%.*s]\n", val->rs.len, val->rs.s);
2659 2650
 	si = grep_sock_info(&host, (unsigned short)port, (unsigned short)proto);
2660 2651
 	if (si!=NULL)
... ...
@@ -13,8 +13,8 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  */
20 20
 
... ...
@@ -34,17 +34,16 @@ int pv_parse_select_name(pv_spec_p sp, str *in)
34 34
 	if (in == NULL || in->s == NULL || sp == NULL)
35 35
 		return -1;
36 36
 
37
-	c = in->s[in->len];
38
-	in->s[in->len] = '\0';
37
+	STR_VTOZ(in->s[in->len], c);
39 38
 	p = in->s;
40 39
 	if(parse_select(&p, &sel)<0)
41 40
 	{
42 41
 		LM_ERR("invalid select name [%.*s]\n",
43 42
 				in->len, in->s);
44
-		in->s[in->len] = c;
43
+		STR_ZTOV(in->s[in->len], c);
45 44
 		return -1;
46 45
 	}
47
-	in->s[in->len] = c;
46
+	STR_ZTOV(in->s[in->len], c);
48 47
 	sp->pvp.pvn.u.dname = (void*)sel;
49 48
 	sp->pvp.pvn.type = PV_NAME_OTHER;
50 49
 	return 0;