Skip to content

Commit bb26c48

Browse files
committed
libtrap: check return value of t_rb_at() to get next container
If t_rb_at() returns NULL, we cannot access its content (such as the buffer or ref_counter). There is currently continue after this test to go back to the start of the loop and check is_terminated.
1 parent b363087 commit bb26c48

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

libtrap/src/ifc_tcpip.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,10 @@ send_blocking_mode(void *arg)
11261126

11271127
// get next container
11281128
t_cont = t_rb_at(&c->t_mbuf.to_send, cl->container_id);
1129+
if (t_cont == NULL) {
1130+
// we cannot operate with NULL t_cont
1131+
continue;
1132+
}
11291133

11301134
buffer = t_cont->buffer;
11311135
pending_bytes = t_cont->used_bytes;
@@ -1192,6 +1196,10 @@ send_non_blocking_mode(void *arg)
11921196

11931197
// get next container
11941198
t_cont = t_rb_at(&c->t_mbuf.to_send, cl->container_id);
1199+
if (t_cont == NULL) {
1200+
// we cannot operate with NULL t_cont
1201+
continue;
1202+
}
11951203

11961204
// container is no longer available
11971205
if (t_cont_acquiere(t_cont) < 1 || __sync_fetch_and_add(&t_cont->idx, 0) != cl->container_id) {

libtrap/src/ifc_tls.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,10 @@ send_blocking_mode(void *arg)
13131313

13141314
// get next container
13151315
t_cont = t_rb_at(&c->t_mbuf.to_send, cl->container_id);
1316+
if (t_cont == NULL) {
1317+
// we cannot operate with NULL t_cont
1318+
continue;
1319+
}
13161320

13171321
buffer = t_cont->buffer;
13181322
pending_bytes = t_cont->used_bytes;
@@ -1379,6 +1383,10 @@ send_non_blocking_mode(void *arg)
13791383

13801384
// get next container
13811385
t_cont = t_rb_at(&c->t_mbuf.to_send, cl->container_id);
1386+
if (t_cont == NULL) {
1387+
// we cannot operate with NULL t_cont
1388+
continue;
1389+
}
13821390

13831391
// container is no longer available
13841392
if (t_cont_acquiere(t_cont) < 1 || __sync_fetch_and_add(&t_cont->idx, 0) != cl->container_id) {

0 commit comments

Comments
 (0)