Skip to content

Commit d71de09

Browse files
committed
fix: add input validation and logging in incr_send_window function
Signed-off-by: Dengfeng Liu <liudf0716@gmail.com>
1 parent eaef0da commit d71de09

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

tcpmux.c

+24-7
Original file line numberDiff line numberDiff line change
@@ -626,23 +626,40 @@ static int process_data(struct tmux_stream *stream, uint32_t length,
626626
static int incr_send_window(struct bufferevent *bev,
627627
struct tcp_mux_header *tmux_hdr, uint16_t flags,
628628
struct tmux_stream *stream) {
629-
if (!stream) {
629+
// Validate input parameters
630+
if (!bev || !tmux_hdr || !stream) {
631+
debug(LOG_ERR, "Invalid parameters in incr_send_window");
630632
return 0;
631633
}
632-
uint32_t id = stream->id;
633634

634-
if (!process_flags(flags, stream))
635+
// Save stream ID for later use
636+
uint32_t stream_id = stream->id;
637+
638+
// Process control flags first
639+
if (!process_flags(flags, stream)) {
640+
debug(LOG_ERR, "Failed to process flags for stream %d", stream_id);
635641
return 0;
642+
}
636643

637-
if (!get_stream_by_id(id)) {
644+
// Verify stream still exists after flag processing
645+
if (!get_stream_by_id(stream_id)) {
646+
debug(LOG_DEBUG, "Stream %d no longer exists", stream_id);
638647
return 1;
639648
}
640649

641-
uint32_t length = ntohl(tmux_hdr->length);
650+
// Get window increment size
651+
uint32_t increment = ntohl(tmux_hdr->length);
642652

643-
if (stream->send_window == 0)
653+
// Enable read events if window was previously full
654+
if (stream->send_window == 0) {
655+
debug(LOG_DEBUG, "Enabling read events for stream %d", stream_id);
644656
bufferevent_enable(bev, EV_READ);
645-
stream->send_window += length;
657+
}
658+
659+
// Update send window
660+
stream->send_window += increment;
661+
debug(LOG_DEBUG, "Stream %d send window increased by %u to %u",
662+
stream_id, increment, stream->send_window);
646663

647664
return 1;
648665
}

0 commit comments

Comments
 (0)