From 328fd66c1eff40d2d96e79dfce5887d1baef20ff Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Thu, 5 Dec 2019 16:35:23 -0700 Subject: [PATCH 1/3] use off_t type with pwrite/pread --- src/port.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/port.c b/src/port.c index dd4d65bf..99e50443 100644 --- a/src/port.c +++ b/src/port.c @@ -122,7 +122,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode) int wPwrite(WFD fd, unsigned char* buf, unsigned int sz, const unsigned int* shortOffset) { - long offset = ((long)shortOffset[1] << 32) | shortOffset[0]; + off_t offset = ((off_t)shortOffset[1] << 32) | shortOffset[0]; return (int)pwrite(fd, buf, sz, offset); } @@ -130,7 +130,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode) int wPread(WFD fd, unsigned char* buf, unsigned int sz, const unsigned int* shortOffset) { - long offset = ((long)shortOffset[1] << 32) | shortOffset[0]; + off_t offset = ((off_t)shortOffset[1] << 32) | shortOffset[0]; return (int)pread(fd, buf, sz, offset); } From c5228e0fd593f2ea662297488810b2bf8dd93c2a Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Thu, 5 Dec 2019 18:22:43 -0700 Subject: [PATCH 2/3] add check on off_t size to build --- configure.ac | 1 + src/port.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 6dd84043..bcff4ccf 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,7 @@ AC_PROG_INSTALL AC_HEADER_STDC AC_CHECK_SIZEOF([long long]) AC_CHECK_SIZEOF([long]) +AC_CHECK_SIZEOF([off_t]) # Check headers/libs AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday inet_ntoa memset socket]) diff --git a/src/port.c b/src/port.c index 99e50443..9948720a 100644 --- a/src/port.c +++ b/src/port.c @@ -85,6 +85,16 @@ int wfopen(WFILE** f, const char* filename, const char* mode) #if (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) && \ !defined(NO_WOLFSSH_SERVER) + #ifndef SIZEOF_OFF_T + /* if not using autoconf then make a guess on off_t size based on sizeof + * long long */ + #if defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG == 8 + #define SIZEOF_OFF_T 8 + #else + #define SIZEOF_OFF_T 4 + #endif + #endif + #if defined(USE_WINDOWS_API) || defined(WOLFSSL_NUCLEUS) || \ defined(FREESCALE_MQX) @@ -122,7 +132,11 @@ int wfopen(WFILE** f, const char* filename, const char* mode) int wPwrite(WFD fd, unsigned char* buf, unsigned int sz, const unsigned int* shortOffset) { - off_t offset = ((off_t)shortOffset[1] << 32) | shortOffset[0]; + off_t offset = (off_t)shortOffset[0]; + + #if SIZEOF_OFF_T == 8 + offset = ((off_t)shortOffset[1] << 32) | offset; + #endif return (int)pwrite(fd, buf, sz, offset); } @@ -130,7 +144,11 @@ int wfopen(WFILE** f, const char* filename, const char* mode) int wPread(WFD fd, unsigned char* buf, unsigned int sz, const unsigned int* shortOffset) { - off_t offset = ((off_t)shortOffset[1] << 32) | shortOffset[0]; + off_t offset = (off_t)shortOffset[0]; + + #if SIZEOF_OFF_T == 8 + offset = ((off_t)shortOffset[1] << 32) | offset; + #endif return (int)pread(fd, buf, sz, offset); } From 526ca192b35667eb1dc388e27f883f4c9dccd7e9 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 6 Dec 2019 09:55:18 -0700 Subject: [PATCH 3/3] add check for shifting stats.st_size (type off_t) --- src/port.c | 2 +- src/wolfsftp.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/port.c b/src/port.c index 9948720a..4bb90bbc 100644 --- a/src/port.c +++ b/src/port.c @@ -88,7 +88,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode) #ifndef SIZEOF_OFF_T /* if not using autoconf then make a guess on off_t size based on sizeof * long long */ - #if defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG == 8 + #if defined(SIZEOF_LONG) && SIZEOF_LONG == 8 #define SIZEOF_OFF_T 8 #else #define SIZEOF_OFF_T 4 diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 3c759e7c..fcfab126 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -3807,7 +3807,9 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr, atr->flags |= WOLFSSH_FILEATRB_SIZE; atr->sz[0] = (word32)(stats.st_size & 0xFFFFFFFF); +#if SIZEOF_OFF_T == 8 atr->sz[1] = (word32)((stats.st_size >> 32) & 0xFFFFFFFF); +#endif atr->flags |= WOLFSSH_FILEATRB_UIDGID; atr->uid = (word32)stats.st_uid; @@ -3849,7 +3851,9 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz, atr->flags |= WOLFSSH_FILEATRB_SIZE; atr->sz[0] = (word32)(stats.st_size & 0xFFFFFFFF); +#if SIZEOF_OFF_T == 8 atr->sz[1] = (word32)((stats.st_size >> 32) & 0xFFFFFFFF); +#endif atr->flags |= WOLFSSH_FILEATRB_UIDGID; atr->uid = (word32)stats.st_uid;