2
0
Эх сурвалжийг харах

core: tcp - safety checks on emptly local tcp connection list

Daniel-Constantin Mierla 5 жил өмнө
parent
commit
67f9de8a94
1 өөрчлөгдсөн 21 нэмэгдсэн , 16 устгасан
  1. 21 16
      src/core/tcp_read.c

+ 21 - 16
src/core/tcp_read.c

@@ -1689,10 +1689,10 @@ void release_tcpconn(struct tcp_connection* c, long state, int unix_sock)
 static ticks_t tcpconn_read_timeout(ticks_t t, struct timer_ln* tl, void* data)
 {
 	struct tcp_connection *c;
-	
-	c=(struct tcp_connection*)data; 
+
+	c=(struct tcp_connection*)data;
 	/* or (struct tcp...*)(tl-offset(c->timer)) */
-	
+
 	if (likely(!(c->state<0) && TICKS_LT(t, c->timeout))){
 		/* timeout extended, exit */
 		return (ticks_t)(c->timeout - t);
@@ -1706,9 +1706,10 @@ static ticks_t tcpconn_read_timeout(ticks_t t, struct timer_ln* tl, void* data)
 					ip_addr2a(&c->rcv.src_ip), c->rcv.src_port,
 					ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port);
 	}
-	tcpconn_listrm(tcp_conn_lst, c, c_next, c_prev);
-	release_tcpconn(c, (c->state<0)?CONN_ERROR:CONN_RELEASE, tcpmain_sock);
-	
+	if(tcp_conn_lst!=NULL) {
+		tcpconn_listrm(tcp_conn_lst, c, c_next, c_prev);
+		release_tcpconn(c, (c->state<0)?CONN_ERROR:CONN_RELEASE, tcpmain_sock);
+	}
 	return 0;
 }
 
@@ -1836,8 +1837,10 @@ repeat_1st_read:
 							ip_addr2a(&ec->rcv.dst_ip), ec->rcv.dst_port);
 
 				}
-				tcpconn_listrm(tcp_conn_lst, con, c_next, c_prev);
-				local_timer_del(&tcp_reader_ltimer, &con->timer);
+				if(tcp_conn_lst!=NULL) {
+					tcpconn_listrm(tcp_conn_lst, con, c_next, c_prev);
+					local_timer_del(&tcp_reader_ltimer, &con->timer);
+				}
 				goto con_error;
 			}
 			break;
@@ -1877,11 +1880,13 @@ read_error:
 							ip_addr2a(&con->rcv.src_ip), con->rcv.src_port,
 							ip_addr2a(&con->rcv.dst_ip), con->rcv.dst_port);
 				}
-				tcpconn_listrm(tcp_conn_lst, con, c_next, c_prev);
-				local_timer_del(&tcp_reader_ltimer, &con->timer);
-				if (unlikely(resp!=CONN_EOF))
-					con->state=S_CONN_BAD;
-				release_tcpconn(con, resp, tcpmain_sock);
+				if(tcp_conn_lst!=NULL) {
+					tcpconn_listrm(tcp_conn_lst, con, c_next, c_prev);
+					local_timer_del(&tcp_reader_ltimer, &con->timer);
+					if (unlikely(resp!=CONN_EOF))
+						con->state=S_CONN_BAD;
+					release_tcpconn(con, resp, tcpmain_sock);
+				}
 			}else{
 #ifdef USE_TLS
 				if (unlikely(read_flags & RD_CONN_REPEAT_READ))
@@ -1889,8 +1894,8 @@ read_error:
 #endif /* USE_TLS */
 				/* update timeout */
 				con->timeout=get_ticks_raw()+S_TO_TICKS(TCP_CHILD_TIMEOUT);
-				/* ret= 0 (read the whole socket buffer) if short read & 
-				 *  !POLLPRI,  bytes read otherwise */
+				/* ret= 0 (read the whole socket buffer) if short read
+				 * & !POLLPRI,  bytes read otherwise */
 				ret&=(((read_flags & RD_CONN_SHORT_READ) &&
 						!(events & POLLPRI)) - 1);
 			}
@@ -1904,7 +1909,7 @@ read_error:
 			LM_CRIT("unknown fd type %d\n", fm->type);
 			goto error;
 	}
-	
+
 	return ret;
 con_error:
 	con->state=S_CONN_BAD;