Skip to content

Commit 1762685

Browse files
TristanInSecvszakats
authored andcommitted
packet: check _libssh2_get_string() return in EXT_INFO handler
The `SSH_MSG_EXT_INFO` handler discards the return values from `_libssh2_get_string()` when parsing extension name/value pairs. When the buffer is exhausted before all claimed extensions are parsed, the loop continues with no-op iterations until `nr_extensions` reaches zero. The `nr_extensions >= 1024` cap limits the worst case, but the loop should still break on parse failure for correctness and consistency with other parsers in this file (e.g. `SSH_MSG_CHANNEL_OPEN`, `SSH_MSG_KEXINIT`) that check `_libssh2_get_string()` return values. Closes #1864
1 parent 5a54b7c commit 1762685

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/packet.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,10 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
890890

891891
nr_extensions -= 1;
892892

893-
_libssh2_get_string(&buf, &name, &name_len);
894-
_libssh2_get_string(&buf, &value, &value_len);
893+
if(_libssh2_get_string(&buf, &name, &name_len))
894+
break;
895+
if(_libssh2_get_string(&buf, &value, &value_len))
896+
break;
895897

896898
if(name && value) {
897899
_libssh2_debug((session,

0 commit comments

Comments
 (0)