Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void common_session_init(int sock_in, int sock_out) {
ses.lastpacket = 0;
ses.reply_queue_head = NULL;
ses.reply_queue_tail = NULL;
ses.reply_queue_len = 0;

/* set all the algos to none */
ses.keys = (struct key_context*)m_malloc(sizeof(struct key_context));
Expand Down
8 changes: 8 additions & 0 deletions src/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ static int packet_is_okay_kex(unsigned char type) {

static void enqueue_reply_packet(void) {
struct packetlist * new_item = NULL;

if (ses.reply_queue_len > MAX_DEFER_REPLY_QUEUE) {
/* This limit should never be reached by a normal peer. */
dropbear_exit("Full reply queue");
}

new_item = m_malloc(sizeof(struct packetlist));
new_item->next = NULL;

Expand All @@ -490,6 +496,7 @@ static void enqueue_reply_packet(void) {
ses.reply_queue_head = new_item;
}
ses.reply_queue_tail = new_item;
ses.reply_queue_len++;
}

void maybe_flush_reply_queue() {
Expand All @@ -512,6 +519,7 @@ void maybe_flush_reply_queue() {
encrypt_packet();
}
ses.reply_queue_head = ses.reply_queue_tail = NULL;
ses.reply_queue_len = 0;
}

/* encrypt the writepayload, putting into writebuf, ready for write_packet()
Expand Down
1 change: 1 addition & 0 deletions src/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ struct sshsession {
/* a list of queued replies that should be sent after a KEX has
concluded (ie, while dataallowed was unset)*/
struct packetlist *reply_queue_head, *reply_queue_tail;
size_t reply_queue_len;

void(*remoteclosed)(void); /* A callback to handle closure of the
remote connection */
Expand Down
4 changes: 4 additions & 0 deletions src/sysoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@
#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
MAX_CMD_LEN is usually longer */

/* Count of packets ot enqueue deferring while a KEX is in progress.
* We wouldn't expect to be anywhere near one-per-channel in normal
* operation, but all replies are small so this is a reasonable upper bound */
#define MAX_DEFER_REPLY_QUEUE MAX_CHANNELS

/* Key type sizes are ordered large to small, all are
determined empirically, and rounded up */
Expand Down