Skip to content

Commit 03137e3

Browse files
committed
Add a check on the maximum allowed SSH payload (vs packet) length, to mirror what is done in mod_sftp, and to hopefully quell some CodeQL nits about uncontrolled allocation sizes.
1 parent 81fde88 commit 03137e3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/proxy/ssh/packet.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy SSH packet IO
3-
* Copyright (c) 2021-2023 TJ Saunders
3+
* Copyright (c) 2021-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -1121,6 +1121,20 @@ static int check_packet_lengths(conn_t *conn, struct proxy_ssh_packet *pkt) {
11211121
return -1;
11221122
}
11231123

1124+
/* XXX I'm not so sure about this check; we SHOULD have a maximum payload
1125+
* check, but using the max packet length check for the payload length seems
1126+
* awkward. Still, better than nothing.
1127+
*/
1128+
if (pkt->payload_len > PROXY_SSH_MAX_PACKET_LEN) {
1129+
(void) pr_log_writefile(proxy_logfd, MOD_PROXY_VERSION,
1130+
"payload length too long (%lu), exceeds maximum payload length (%lu) "
1131+
"(packet len %lu, padding len %u)", (unsigned long) pkt->payload_len,
1132+
(unsigned long) PROXY_SSH_MAX_PACKET_LEN, (unsigned long) pkt->packet_len,
1133+
(unsigned int) pkt->padding_len);
1134+
read_packet_discard(conn);
1135+
return -1;
1136+
}
1137+
11241138
return 0;
11251139
}
11261140

0 commit comments

Comments
 (0)