Browse code

rr: use safer msg_ctx_id_t checks for asserting validity of cached param value

Daniel-Constantin Mierla authored on 30/09/2020 11:09:51
Showing 1 changed files
... ...
@@ -78,7 +78,7 @@ extern int rr_sockname_mode;
78 78
  */
79 79
 static char rr_param_buf_ptr[RR_PARAM_BUF_SIZE];
80 80
 static str rr_param_buf = {rr_param_buf_ptr,0};
81
-static unsigned int rr_param_msg;
81
+static msg_ctx_id_t rr_param_ctx_id = {0};
82 82
 
83 83
 static pv_spec_t *custom_user_avp;		/*!< AVP for custom_user setting */
84 84
 
... ...
@@ -429,7 +429,7 @@ int record_route(struct sip_msg* _m, str *params)
429 429
 		tag = 0;
430 430
 	}
431 431
 
432
-	if (rr_param_buf.len && rr_param_msg!=_m->id) {
432
+	if (rr_param_buf.len && (msg_ctx_id_match(_m, &rr_param_ctx_id)!=1)) {
433 433
 		/* rr_params were set for a different message -> reset buffer */
434 434
 		rr_param_buf.len = 0;
435 435
 	}
... ...
@@ -549,7 +549,7 @@ int record_route_preset(struct sip_msg* _m, str* _data)
549 549
 		from = get_from(_m);
550 550
 	}
551 551
 
552
-	if (rr_param_buf.len && rr_param_msg!=_m->id) {
552
+	if (rr_param_buf.len && (msg_ctx_id_match(_m, &rr_param_ctx_id)!=1)) {
553 553
 		/* rr_params were set for a different message -> reset buffer */
554 554
 		rr_param_buf.len = 0;
555 555
 	}
... ...
@@ -817,7 +817,7 @@ int record_route_advertised_address(struct sip_msg* _m, str* _data)
817 817
 		tag = 0;
818 818
 	}
819 819
 
820
-	if (rr_param_buf.len && rr_param_msg!=_m->id) {
820
+	if (rr_param_buf.len && (msg_ctx_id_match(_m, &rr_param_ctx_id)!=1)) {
821 821
 		/* rr_params were set for a different message -> reset buffer */
822 822
 		rr_param_buf.len = 0;
823 823
 	}
... ...
@@ -930,10 +930,10 @@ int add_rr_param(struct sip_msg* msg, str* rr_param)
930 930
 		}
931 931
 	} else {
932 932
 		/* RR not done yet -> store the param in the static buffer */
933
-		if (rr_param_msg!=msg->id) {
933
+		if (msg_ctx_id_match(msg, &rr_param_ctx_id)!=1) {
934 934
 			/* it's about a different message -> reset buffer */
935 935
 			rr_param_buf.len = 0;
936
-			rr_param_msg = msg->id;
936
+			msg_ctx_id_set(msg, &rr_param_ctx_id);
937 937
 		}
938 938
 		if (rr_param_buf.len+rr_param->len>RR_PARAM_BUF_SIZE) {
939 939
 			LM_ERR("maximum size of rr_param_buf exceeded\n");