Skip to content

Commit 4cb8d1e

Browse files
committed
Fix buffer over-read in wolfSSH_DoModes terminal mode parsing
The while loop condition only checked that the opcode byte was in bounds (idx < modesSz) but not the 4-byte argument read by ato32(). When modesSz had a remainder of 1 mod 5 and the trailing byte was a valid opcode (1-159) rather than TTY_OP_END, ato32() would read 4 bytes past the buffer. Change the loop guard to require a full TERMINAL_MODE_SZ bytes remaining before entering the loop body.
1 parent 46cd6a7 commit 4cb8d1e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/internal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8944,7 +8944,7 @@ int wolfSSH_DoModes(const byte* modes, word32 modesSz, int fd)
89448944

89458945
tcgetattr(fd, &term);
89468946

8947-
while (idx < modesSz && modes[idx] != WOLFSSH_TTY_OP_END
8947+
while (idx + TERMINAL_MODE_SZ <= modesSz && modes[idx] != WOLFSSH_TTY_OP_END
89488948
&& modes[idx] < WOLFSSH_TTY_INVALID) {
89498949

89508950
ato32(modes + idx + 1, &arg);

0 commit comments

Comments
 (0)