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
16 changes: 13 additions & 3 deletions apps/wolfssh/wolfssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,22 @@ static int NonBlockSSH_connect(WOLFSSH* ssh)

#if defined(HAVE_TERMIOS_H) && defined(WOLFSSH_TERM)
WOLFSSH_TERMIOS oldTerm;
/* Set while oldTerm holds the stdin modes and stdin may be in raw mode. */
static int termSaved = 0;

static void modes_store(void)
{
tcgetattr(STDIN_FILENO, &oldTerm);
termSaved = (tcgetattr(STDIN_FILENO, &oldTerm) == 0);
}

static void modes_clear(void)
{
WOLFSSH_TERMIOS term = oldTerm;

if (!termSaved) {
return;
}

term.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOE
| ECHOK | ECHONL | NOFLSH | TOSTOP);

Expand Down Expand Up @@ -245,12 +251,16 @@ static void modes_clear(void)
#ifdef CRTSCTS
term.c_cflag &= ~(CRTSCTS);
#endif
tcsetattr(STDIN_FILENO, TCSANOW, &term);
if (tcsetattr(STDIN_FILENO, TCSANOW, &term) != 0) {
termSaved = 0;
}
}

static void modes_reset(void)
{
tcsetattr(STDIN_FILENO, TCSAFLUSH, &oldTerm);
if (termSaved) {
(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &oldTerm);
}
}

#define MODES_STORE() modes_store()
Expand Down
11 changes: 5 additions & 6 deletions apps/wolfsshd/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ static int ConfigLoad(WOLFSSHD_CONFIG* conf, const char* filename, int depth);
static int CountWhitespace(const char* in, int inSz, byte inv);
static int SetFileString(char** dst, const char* src, void* heap);

/* Largest value GetConfigInt returns, before and after a time multiplier. It
* fits in a long on every target. */
#define CONFIG_INT_MAX 0x7FFFFFFFL
/* Largest value GetConfigInt returns, before and after a time multiplier. */
#define CONFIG_INT_MAX 0x7FFFFFFF

/* Convert a decimal string into a number. With isTime, the string is the
* sshd_config(5) time format: one or more groups of a number and a unit
Expand All @@ -148,7 +147,7 @@ static int SetFileString(char** dst, const char* src, void* heap);
* Returns the value on success and negative value on failure */
static long GetConfigInt(const char* in, int inSz, int isTime, void* heap)
{
long total = 0;
int total = 0;
int i = 0;

(void)heap;
Expand All @@ -158,8 +157,8 @@ static long GetConfigInt(const char* in, int inSz, int isTime, void* heap)
}

do {
long val = 0;
long mult = 1; /* multiplier */
int val = 0;
int mult = 1; /* multiplier */
int start = i;

for (; i < inSz && in[i] >= '0' && in[i] <= '9'; i++) {
Expand Down
19 changes: 15 additions & 4 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ int wolfSSH_TestSftpSendPacketType(WOLFSSH* ssh, byte type, byte* buf,

/* returns the amount read on success */
static int wolfSSH_SFTP_buffer_read(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer,
int readSz)
word32 readSz)
{
int ret;
int polled;
Expand All @@ -766,6 +766,11 @@ static int wolfSSH_SFTP_buffer_read(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer,
return 0;
}

/* The size is returned as an int. */
if (readSz > (word32)0x7FFFFFFF || buffer->sz > (word32)0x7FFFFFFF) {
return WS_BUFFER_E;
}

if (buffer->data == NULL) {
buffer->idx = 0;
buffer->sz = readSz;
Expand Down Expand Up @@ -842,7 +847,7 @@ static int wolfSSH_SFTP_buffer_read(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer,
buffer->sz);
} while (buffer->idx < buffer->sz);

return buffer->sz;
return (int)buffer->sz;
}


Expand Down Expand Up @@ -1424,7 +1429,7 @@ static int SFTP_ServerRecvInit(WOLFSSH* ssh) {
/* silently ignore extensions if not supported */
if (state->extSz > 0) {
ret = wolfSSH_SFTP_buffer_read(ssh,
&state->buffer, (int)state->extSz);
&state->buffer, state->extSz);
if (ret < 0) {
return WS_FATAL_ERROR;
}
Expand Down Expand Up @@ -6921,7 +6926,7 @@ static int SFTP_ClientRecvInit(WOLFSSH* ssh) {
/* silently ignore extensions if not supported */
if (state->extSz > 0) {
ret = wolfSSH_SFTP_buffer_read(ssh,
&state->buffer, (int)state->extSz);
&state->buffer, state->extSz);
if (ret < 0) {
return WS_FATAL_ERROR;
}
Expand Down Expand Up @@ -7620,6 +7625,12 @@ static WS_SFTPNAME* wolfSSH_SFTP_DoName(WOLFSSH* ssh)
case SFTP_NAME_GET_PACKET:
/* get number of files */
/* using idx as an offset for partial reads */
if (wolfSSH_SFTP_buffer_idx(&state->buffer) >
wolfSSH_SFTP_buffer_size(&state->buffer)) {
ssh->error = WS_BUFFER_E;
wolfSSH_SFTP_ClearState(ssh, STATE_ID_NAME);
return NULL;
}
ret = wolfSSH_SFTP_buffer_read(ssh, &state->buffer,
wolfSSH_SFTP_buffer_size(&state->buffer) -
wolfSSH_SFTP_buffer_idx(&state->buffer));
Expand Down
Loading