Browse code

pv: do not set ending '\0' for port value in pv_set_ruri_port()

- it can be a reference to a static string, ending up in a crash
- GH #2258

Daniel-Constantin Mierla authored on 19/03/2020 09:59:43
Showing 1 changed files
... ...
@@ -2558,7 +2558,9 @@ int pv_set_ruri_port(struct sip_msg* msg, pv_param_t *param,
2558 2558
 	act.val[0].type = STRING_ST;
2559 2559
 	act.val[0].u.string = val->rs.s;
2560 2560
 	backup = val->rs.s[val->rs.len];
2561
-	val->rs.s[val->rs.len] = '\0';
2561
+	if(backup != '\0') {
2562
+		val->rs.s[val->rs.len] = '\0';
2563
+	}
2562 2564
 	act.type = SET_PORT_T;
2563 2565
 	init_run_actions_ctx(&h);
2564 2566
 	if (do_action(&h, &act, msg)<0)
... ...
@@ -2567,7 +2569,9 @@ int pv_set_ruri_port(struct sip_msg* msg, pv_param_t *param,
2567 2569
 		val->rs.s[val->rs.len] = backup;
2568 2570
 		goto error;
2569 2571
 	}
2570
-	val->rs.s[val->rs.len] = backup;
2572
+	if(backup != '\0') {
2573
+		val->rs.s[val->rs.len] = backup;
2574
+	}
2571 2575
 
2572 2576
 	return 0;
2573 2577
 error: