Skip to content

Commit 32b765e

Browse files
committed
fix: add input validation and debug logging to add_stream function
Signed-off-by: Dengfeng Liu <[email protected]>
1 parent 73674af commit 32b765e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tcpmux.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,23 @@ static struct tmux_stream *all_stream;
5353
* @param stream A pointer to the `tmux_stream` structure to be added.
5454
*/
5555
void add_stream(struct tmux_stream *stream) {
56+
// Validate input parameter
57+
if (!stream) {
58+
debug(LOG_ERR, "Cannot add NULL stream");
59+
return;
60+
}
61+
62+
// Check if stream already exists
63+
struct tmux_stream *existing = NULL;
64+
HASH_FIND_INT(all_stream, &stream->id, existing);
65+
if (existing) {
66+
debug(LOG_WARNING, "Stream %u already exists in hash table", stream->id);
67+
return;
68+
}
69+
70+
// Add stream to hash table
5671
HASH_ADD_INT(all_stream, id, stream);
72+
debug(LOG_DEBUG, "Added stream %u to hash table", stream->id);
5773
}
5874

5975
/**

0 commit comments

Comments
 (0)