Skip to content

Commit 8a02b35

Browse files
authored
Revisit assertions in video conference asynchronous operations (#4530)
Some conference operations, such as connect, disconnect, remove, are asynchronous. There are port validity checks when the request are made. When the op is being executed, there are checks too, but unfortunately in assertion forms. This patch replace the assertions with normal checks (i.e: returning error upon failure).
1 parent 8be8002 commit 8a02b35

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

pjmedia/src/pjmedia/conference.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,10 +1483,12 @@ static pj_status_t op_disconnect_ports(pjmedia_conf *conf,
14831483
return PJ_EINVAL;
14841484
}
14851485

1486+
/* Sanity checks */
14861487
pj_assert(src_port->listener_cnt > 0 &&
14871488
src_port->listener_cnt <= conf->max_ports);
14881489
pj_assert(dst_port->transmitter_cnt > 0 &&
14891490
dst_port->transmitter_cnt <= conf->max_ports);
1491+
14901492
pj_array_erase(src_port->listener_slots, sizeof(SLOT_TYPE),
14911493
src_port->listener_cnt, i);
14921494
pj_array_erase(src_port->listener_adj_level, sizeof(unsigned),
@@ -1863,7 +1865,7 @@ static pj_status_t op_remove_port(pjmedia_conf *conf,
18631865
/* Port must be valid. */
18641866
conf_port = conf->ports[port];
18651867
if (conf_port == NULL) {
1866-
PJ_PERROR(3, (THIS_FILE, PJ_ENOTFOUND, "Remove port failed"));
1868+
PJ_PERROR(3, (THIS_FILE, PJ_EINVAL, "Remove port failed"));
18671869
return PJ_EINVAL;
18681870
}
18691871

pjmedia/src/pjmedia/vid_conf.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,12 @@ static pj_status_t op_remove_port(pjmedia_vid_conf *vid_conf,
720720
vconf_port *cport = vid_conf->ports[slot];
721721
pj_status_t status;
722722

723-
pj_assert(cport);
723+
/* Port must be valid. */
724+
if (!cport) {
725+
PJ_PERROR(3, (THIS_FILE, PJ_EINVAL,
726+
"Failed removing port %d, invalid video port", slot));
727+
return PJ_EINVAL;
728+
}
724729

725730
/* Disconnect slot -> listeners */
726731
while (cport->listener_cnt) {
@@ -937,12 +942,13 @@ static pj_status_t op_connect_ports(pjmedia_vid_conf *vid_conf,
937942
sink_slot = prm->connect_ports.sink;
938943
src_port = vid_conf->ports[src_slot];
939944
dst_port = vid_conf->ports[sink_slot];
940-
pj_assert(src_port && src_port->port && src_port->port->get_frame);
941-
pj_assert(dst_port && dst_port->port && dst_port->port->put_frame);
942945

943-
if (!src_port || !dst_port) {
946+
if (!src_port || !dst_port ||
947+
!src_port->port || !dst_port->port ||
948+
!src_port->port->get_frame || !dst_port->port->put_frame)
949+
{
944950
PJ_PERROR(3, (THIS_FILE, PJ_EINVAL,
945-
"Failed connecting %d->%d, make sure video ports are valid",
951+
"Failed connecting %d->%d, invalid video ports",
946952
src_slot, sink_slot));
947953
return PJ_EINVAL;
948954
}
@@ -1049,7 +1055,12 @@ static pj_status_t op_disconnect_ports(pjmedia_vid_conf *vid_conf,
10491055
sink_slot = prm->disconnect_ports.sink;
10501056
src_port = vid_conf->ports[src_slot];
10511057
dst_port = vid_conf->ports[sink_slot];
1052-
pj_assert(src_port && dst_port);
1058+
if (!src_port || !dst_port) {
1059+
PJ_PERROR(3, (THIS_FILE, PJ_EINVAL,
1060+
"Failed disconnecting %d->%d, invalid video ports",
1061+
src_slot, sink_slot));
1062+
return PJ_EINVAL;
1063+
}
10531064

10541065
/* Check if connection has been made */
10551066
for (i=0; i<src_port->listener_cnt; ++i) {
@@ -1064,6 +1075,7 @@ static pj_status_t op_disconnect_ports(pjmedia_vid_conf *vid_conf,
10641075
if (i == src_port->listener_cnt || j == dst_port->transmitter_cnt)
10651076
return PJ_EINVAL;
10661077

1078+
/* Sanity check: the number of listeners and transmitters. */
10671079
pj_assert(src_port->listener_cnt > 0 &&
10681080
src_port->listener_cnt < vid_conf->opt.max_slot_cnt);
10691081
pj_assert(dst_port->transmitter_cnt > 0 &&
@@ -1658,7 +1670,11 @@ static pj_status_t op_update_port(pjmedia_vid_conf *vid_conf,
16581670
pjmedia_format *new_fmt;
16591671

16601672
/* Port must be valid. */
1661-
pj_assert(cport);
1673+
if (!cport) {
1674+
PJ_PERROR(3, (THIS_FILE, PJ_EINVAL,
1675+
"Failed updating port %d, invalid video port", slot));
1676+
return PJ_EINVAL;
1677+
}
16621678

16631679
/* Get the old & new formats */
16641680
old_fmt = &cport->format;

0 commit comments

Comments
 (0)