Skip to content
Open
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
3 changes: 2 additions & 1 deletion apps/wolfssh/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ static int load_der_file(const char* filename, byte** out, word32* outSz)
if (ret != 0 || file == WBADFILE)
return -1;

if (WFSEEK(NULL, file, 0, WSEEK_END) != 0) {
ret = WFSEEK(NULL, file, 0, WSEEK_END);
if (!WFSEEK_SUCCESS(ret)) {
WFCLOSE(NULL, file);
return -1;
}
Expand Down
3 changes: 2 additions & 1 deletion examples/client/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ static int load_der_file(const char* filename, byte** out, word32* outSz,
if (ret != 0 || file == WBADFILE)
return -1;

if (WFSEEK(NULL, file, 0, WSEEK_END) != 0) {
ret = WFSEEK(NULL, file, 0, WSEEK_END);
if (!WFSEEK_SUCCESS(ret)) {
WFCLOSE(NULL, file);
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
int ret;

ret = (int)WFSEEK(NULL, &fd, shortOffset[0], SYS_FS_SEEK_SET);
if (ret != -1) {
if (WFSEEK_SUCCESS(ret)) {
ret = (int)WFWRITE(NULL, buf, 1, sz, &fd);
}

Expand All @@ -145,7 +145,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
int ret;

ret = (int)WFSEEK(NULL, &fd, shortOffset[0], SYS_FS_SEEK_SET);
if (ret != -1)
if (WFSEEK_SUCCESS(ret))
ret = (int)WFREAD(NULL, buf, 1, sz, &fd);

return ret;
Expand Down
3 changes: 2 additions & 1 deletion src/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,8 @@ int wolfSSH_ReadKey_file(const char* name,
if (ret != 0 || file == WBADFILE) return WS_BAD_FILE_E;
#endif

if (WFSEEK(NULL, file, 0, WSEEK_END) != 0) {
ret = WFSEEK(NULL, file, 0, WSEEK_END);
if (!WFSEEK_SUCCESS(ret)) {
WFCLOSE(NULL, file);
return WS_BAD_FILE_E;
}
Expand Down
3 changes: 2 additions & 1 deletion src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10053,7 +10053,8 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
#if SIZEOF_OFF_T == 8
offset = (((word64)state->pOfst[1]) << 32) | offset;
#endif
if (WFSEEK(ssh->fs, state->fl, offset, 0) != 0) {
ret = WFSEEK(ssh->fs, state->fl, offset, 0);
if (!WFSEEK_SUCCESS(ret)) {
WLOG(WS_LOG_SFTP, "Unable to seek input file");
ssh->error = WS_BAD_FILE_E;
ret = WS_FATAL_ERROR;
Expand Down
9 changes: 9 additions & 0 deletions wolfssh/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ extern "C" {
#define WREWIND(fs,s) NU_Seek(*(s), 0, PSEEK_SET)
#define WSEEK_END PSEEK_END
#define WBADFILE NULL
#define WFSEEK_SUCCESS(r) ((r) >= 0)

#define WS_DELIM '\\'
#define WOLFSSH_O_RDWR PO_RDWR
Expand Down Expand Up @@ -440,6 +441,7 @@ extern "C" {
#define WSETTIME(fs,f,a,m) (0)
#define WFSETTIME(fs,fd,a,m) (0)
#define WCHDIR(fs,b) SYS_FS_DirectryChange((b))
#define WFSEEK_SUCCESS(r) ((r) >= 0)

#else
#include <stdlib.h>
Expand Down Expand Up @@ -1624,6 +1626,13 @@ extern "C" {
#define WOLFSSH_O_NOFOLLOW 0
#endif

/* Catch-all so callers can test a seek result unconditionally. Ports whose
* seek returns a file position rather than a status must define this as
* ((r) >= 0); see the Nucleus and MPLAB Harmony blocks above. */
#ifndef WFSEEK_SUCCESS
#define WFSEEK_SUCCESS(r) ((r) == 0)
#endif

/* wIsSymlink lives in the always-compiled port.c, but its filesystem
* dependencies (WSTAT_T/WLSTAT/S_ISLNK on POSIX, WS_GetFileAttributesExA on
* Windows) and its only callers exist solely in the SFTP and SCP code, so
Expand Down
Loading