Skip to content

Commit

Permalink
fix: enhance tcp_mux_send_data function with input validation and err…
Browse files Browse the repository at this point in the history
…or handling

Signed-off-by: Dengfeng Liu <liudf0716@gmail.com>
  • Loading branch information
liudf0716 committed Nov 13, 2024
1 parent 8c9cfee commit 2b2aa9d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tcpmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,26 @@ void tcp_mux_send_win_update_rst(struct bufferevent *bout, uint32_t stream_id) {
*/
void tcp_mux_send_data(struct bufferevent *bout, uint16_t flags,
uint32_t stream_id, uint32_t length) {
if (!tcp_mux_flag())
// Early return if TCP multiplexing is disabled
if (!tcp_mux_flag()) {
debug(LOG_DEBUG, "TCP multiplexing is disabled");
return;
}

// Validate input parameters
if (!bout) {
debug(LOG_ERR, "Invalid bufferevent for sending data");
return;
}

// Prepare and send header
struct tcp_mux_header tmux_hdr;
memset(&tmux_hdr, 0, sizeof(tmux_hdr));
tcp_mux_encode(DATA, flags, stream_id, length, &tmux_hdr);
bufferevent_write(bout, (uint8_t *)&tmux_hdr, sizeof(tmux_hdr));

if (bufferevent_write(bout, &tmux_hdr, sizeof(tmux_hdr)) < 0) {
debug(LOG_ERR, "Failed to send data header for stream %u", stream_id);
}
}

/**
Expand Down

0 comments on commit 2b2aa9d

Please sign in to comment.