Skip to content

Commit adcb7e1

Browse files
add sanity check for Windows terminal resize
1 parent 7d48298 commit adcb7e1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/internal.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,16 +1096,21 @@ static int WS_TermResize(WOLFSSH* ssh, word32 col, word32 row, word32 colP,
10961096
int ret = WS_SUCCESS;
10971097

10981098
if (term != NULL) {
1099-
char cmd[20];
1100-
int cmdSz = 20;
1099+
char cmd[30]; /* 2 int values (11 chars max) plus \x1b[8 ; t */
1100+
int cmdSz = 30;
11011101
DWORD wrtn = 0;
11021102

11031103
/* VT control sequence for resizing window */
11041104
cmdSz = snprintf(cmd, cmdSz, "\x1b[8;%d;%dt", row, col);
1105-
if (WriteFile(*term, cmd, cmdSz, &wrtn, 0) != TRUE) {
1106-
WLOG(WS_LOG_ERROR, "Issue with pseudo console resize");
1105+
if (cmdSz < 0 || cmdSz >= sizeof(cmd)) {
11071106
ret = WS_FATAL_ERROR;
11081107
}
1108+
else {
1109+
if (WriteFile(*term, cmd, cmdSz, &wrtn, 0) != TRUE) {
1110+
WLOG(WS_LOG_ERROR, "Issue with pseudo console resize");
1111+
ret = WS_FATAL_ERROR;
1112+
}
1113+
}
11091114
}
11101115

11111116
return ret;

0 commit comments

Comments
 (0)