From dba0b8791d67ee8ab039a2247b1e6552af247431 Mon Sep 17 00:00:00 2001 From: Fabio Alemagna <507164+falemagn@users.noreply.github.com> Date: Fri, 14 Apr 2023 16:43:39 +0200 Subject: [PATCH 1/2] Support large file sizes in long file names. --- src/wolfsftp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 47a2ac43a..b79a4f5e5 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -2448,6 +2448,7 @@ static void getDate(char* buf, int len, struct tm* t) * return WS_SUCCESS on success */ static int SFTP_CreateLongName(WS_SFTPNAME* name) { + char size[32]; char perm[11]; int linkCount = 1; /* @TODO set to correct value */ #if defined(XGMTIME) && defined(XSNPRINTF) @@ -2501,7 +2502,9 @@ static int SFTP_CreateLongName(WS_SFTPNAME* name) totalSz += name->fSz; /* size of file name */ totalSz += 7; /* for all ' ' spaces */ - totalSz += 3 + 8 + 8 + 8; /* linkCount + uid + gid + size */ + totalSz += 3 + 8 + 8; /* linkCount + uid + gid */ + sprintf(size, "%8lld", ((long long int)atr->sz[1] << 32) + (long long int)(atr->sz[0])); + totalSz += strlen(size); #else totalSz = name->fSz; #endif @@ -2515,8 +2518,8 @@ static int SFTP_CreateLongName(WS_SFTPNAME* name) name->lName[totalSz] = '\0'; #if defined(XGMTIME) && defined(XSNPRINTF) - WSNPRINTF(name->lName, totalSz, "%s %3d %8d %8d %8d %s %s", - perm, linkCount, atr->uid, atr->gid, atr->sz[0], date, name->fName); + WSNPRINTF(name->lName, totalSz, "%s %3d %8d %8d %s %s %s", + perm, linkCount, atr->uid, atr->gid, size, date, name->fName); #else WMEMCPY(name->lName, name->fName, totalSz); #endif From efa7188b6dae8f47c948dd43b99c192f066c888b Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Tue, 8 Aug 2023 09:37:35 -0600 Subject: [PATCH 2/2] use WSNPRINTF and rename variable --- src/wolfsftp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index b79a4f5e5..dda4f4818 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -2448,7 +2448,7 @@ static void getDate(char* buf, int len, struct tm* t) * return WS_SUCCESS on success */ static int SFTP_CreateLongName(WS_SFTPNAME* name) { - char size[32]; + char sizeStr[32]; char perm[11]; int linkCount = 1; /* @TODO set to correct value */ #if defined(XGMTIME) && defined(XSNPRINTF) @@ -2503,8 +2503,8 @@ static int SFTP_CreateLongName(WS_SFTPNAME* name) totalSz += name->fSz; /* size of file name */ totalSz += 7; /* for all ' ' spaces */ totalSz += 3 + 8 + 8; /* linkCount + uid + gid */ - sprintf(size, "%8lld", ((long long int)atr->sz[1] << 32) + (long long int)(atr->sz[0])); - totalSz += strlen(size); + WSNPRINTF(sizeStr, sizeof(sizeStr) - 1, "%8lld", ((long long int)atr->sz[1] << 32) + (long long int)(atr->sz[0])); + totalSz += WSTRLEN(sizeStr); #else totalSz = name->fSz; #endif @@ -2519,7 +2519,7 @@ static int SFTP_CreateLongName(WS_SFTPNAME* name) #if defined(XGMTIME) && defined(XSNPRINTF) WSNPRINTF(name->lName, totalSz, "%s %3d %8d %8d %s %s %s", - perm, linkCount, atr->uid, atr->gid, size, date, name->fName); + perm, linkCount, atr->uid, atr->gid, sizeStr, date, name->fName); #else WMEMCPY(name->lName, name->fName, totalSz); #endif