Browse code

imc: safety checks for function parameters

Daniel-Constantin Mierla authored on 14/04/2021 10:40:19
Showing 1 changed files
... ...
@@ -488,6 +488,10 @@ int imc_handle_join(struct sip_msg* msg, imc_cmd_t *cmd,
488 488
 	str body;
489 489
 	struct imc_uri room;
490 490
 
491
+	if(cmd==NULL || src==NULL || dst==NULL) {
492
+		return -1;
493
+	}
494
+
491 495
 	memset(&room, '\0', sizeof(room));
492 496
 	if (build_imc_uri(&room, cmd->param[0].s ? cmd->param[0] : dst->parsed.user, &dst->parsed))
493 497
 		goto error;
... ...
@@ -537,12 +541,14 @@ int imc_handle_join(struct sip_msg* msg, imc_cmd_t *cmd,
537 541
 			goto error;
538 542
 		}
539 543
 
540
-		body.len = snprintf(body.s, sizeof(imc_body_buf), msg_user_joined.s, STR_FMT(format_uri(src->uri)));
544
+		body.len = snprintf(body.s, sizeof(imc_body_buf), msg_user_joined.s,
545
+				STR_FMT(format_uri(src->uri)));
541 546
 	} else {
542 547
 		LM_DBG("Attept to join private room [%.*s] by [%.*s]\n",
543 548
 			STR_FMT(&rm->uri), STR_FMT(&src->uri));
544 549
 
545
-		body.len = snprintf(body.s, sizeof(imc_body_buf), msg_join_attempt_bcast.s, STR_FMT(format_uri(src->uri)));
550
+		body.len = snprintf(body.s, sizeof(imc_body_buf), msg_join_attempt_bcast.s,
551
+				STR_FMT(format_uri(src->uri)));
546 552
 		imc_send_message(&rm->uri, &src->uri, build_headers(msg), &msg_join_attempt_ucast);
547 553
 	}
548 554
 
... ...
@@ -563,7 +569,7 @@ done:
563 569
 
564 570
 	rv = 0;
565 571
 error:
566
-	if (room.uri.s) pkg_free(room.uri.s);
572
+	if (room.uri.s != NULL) pkg_free(room.uri.s);
567 573
 	if (rm != NULL) imc_release_room(rm);
568 574
 	return rv;
569 575
 }