From 948b545ad84648b193f94176b604f52cffd5727e Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 22 Dec 2023 14:43:34 -0800 Subject: [PATCH] Release v1.4.15: Release Testing Fixes 1. Fix an instance in the example sftpclient where the size of something is treated as an int and may have caused trouble, per the pedantic compiler settings. 2. Changed a check for snprintf where we checked the lengths of everything before calling snprintf. Turned it around where we check the return of snprintf and error if the process would have output too much. --- examples/sftpclient/sftpclient.c | 22 +++++++++++----------- src/wolfsftp.c | 20 ++++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/sftpclient/sftpclient.c b/examples/sftpclient/sftpclient.c index 9e1a7d4d..38b07982 100644 --- a/examples/sftpclient/sftpclient.c +++ b/examples/sftpclient/sftpclient.c @@ -714,37 +714,37 @@ static int doCmds(func_args* args) } if ((pt = WSTRNSTR(msg, "chmod", MAX_CMD_SZ)) != NULL) { - int sz; + word32 sz, idx; char* f = NULL; char mode[WOLFSSH_MAX_OCTET_LEN]; pt += sizeof("chmod"); - sz = (int)WSTRLEN(pt); + sz = (word32)WSTRLEN(pt); if (pt[sz - 1] == '\n') pt[sz - 1] = '\0'; /* advance pointer to first location of non space character */ - for (i = 0; i < sz && pt[0] == ' '; i++, pt++); - sz = (int)WSTRLEN(pt); + for (idx = 0; idx < sz && pt[0] == ' '; idx++, pt++); + sz = (word32)WSTRLEN(pt); /* get mode */ sz = (sz < WOLFSSH_MAX_OCTET_LEN - 1)? sz : WOLFSSH_MAX_OCTET_LEN -1; WMEMCPY(mode, pt, sz); mode[WOLFSSH_MAX_OCTET_LEN - 1] = '\0'; - for (i = 0; i < sz; i++) { - if (mode[i] == ' ') { - mode[i] = '\0'; + for (idx = 0; idx < sz; idx++) { + if (mode[idx] == ' ') { + mode[idx] = '\0'; break; } } - if (i == 0) { + if (idx == 0) { printf("error with getting mode\r\n"); continue; } - pt += (int)WSTRLEN(mode); - sz = (int)WSTRLEN(pt); - for (i = 0; i < sz && pt[0] == ' '; i++, pt++); + pt += (word32)WSTRLEN(mode); + sz = (word32)WSTRLEN(pt); + for (idx = 0; idx < sz && pt[0] == ' '; idx++, pt++); if (pt[0] != '/') { int maxSz = (int)WSTRLEN(workingDir) + sz + 2; diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 3bc55c09..e32d09d0 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -2699,12 +2699,12 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out, char s[WOLFSSH_MAX_FILENAME]; if (!special) { /* do not add dir name in special case */ - if (WSTRLEN(dirName) + out->fSz + 2 > (sizeof r)) { + if (WSNPRINTF(r, sizeof(r), "%s/%s", dirName, out->fName) + >= (int)sizeof(r)) { WLOG(WS_LOG_SFTP, "Path length too large"); WFREE(out->fName, out->heap, DYNTYPE_SFTP); return WS_FATAL_ERROR; } - WSNPRINTF(r, sizeof(r), "%s/%s", dirName, out->fName); } else { if (out->fSz + 1 > (sizeof r)) { @@ -2789,12 +2789,12 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out, char r[WOLFSSH_MAX_FILENAME]; char s[WOLFSSH_MAX_FILENAME]; - if ((WSTRLEN(dirName) + WSTRLEN(out->fName) + 2) > sizeof(r)) { + if (WSNPRINTF(r, sizeof(r), "%s/%s", dirName, out->fName) + >= (int)sizeof(r)) { WLOG(WS_LOG_SFTP, "Path length too large"); WFREE(out->fName, out->heap, DYNTYPE_SFTP); return WS_FATAL_ERROR; } - WSNPRINTF(r, sizeof(r), "%s/%s", dirName, out->fName); if (wolfSSH_RealPath(ssh->sftpDefaultPath, r, s, sizeof(s)) < 0) { WLOG(WS_LOG_SFTP, "Error cleaning path to get attributes"); @@ -2954,12 +2954,12 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out, char r[WOLFSSH_MAX_FILENAME]; char s[WOLFSSH_MAX_FILENAME]; - if ((WSTRLEN(dirName) + WSTRLEN(out->fName) + 2) > sizeof(r)) { + if (WSNPRINTF(r, sizeof(r), "%s/%s", dirName, out->fName) + >= (int)sizeof(r)) { WLOG(WS_LOG_SFTP, "Path length too large"); WFREE(out->fName, out->heap, DYNTYPE_SFTP); return WS_FATAL_ERROR; } - WSNPRINTF(r, sizeof(r), "%s/%s", dirName, out->fName); if (wolfSSH_RealPath(ssh->sftpDefaultPath, r, s, sizeof(s)) < 0) { WLOG(WS_LOG_SFTP, "Error cleaning path to get attributes"); @@ -3020,12 +3020,12 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out, char r[WOLFSSH_MAX_FILENAME]; char s[WOLFSSH_MAX_FILENAME]; - if ((WSTRLEN(dirName) + WSTRLEN(out->fName) + 2) > sizeof(r)) { + if (WSNPRINTF(r, sizeof(r), "%s/%s", dirName, out->fName) + >= (int)sizeof(r)) { WLOG(WS_LOG_SFTP, "Path length too large"); WFREE(out->fName, out->heap, DYNTYPE_SFTP); return WS_FATAL_ERROR; } - WSNPRINTF(r, sizeof(r), "%s/%s", dirName, out->fName); if (wolfSSH_RealPath(ssh->sftpDefaultPath, r, s, sizeof(s)) < 0) { WFREE(out->fName, out->heap, DYNTYPE_SFTP); @@ -3087,12 +3087,12 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out, char r[WOLFSSH_MAX_FILENAME]; char s[WOLFSSH_MAX_FILENAME]; - if ((WSTRLEN(dirName) + WSTRLEN(out->fName) + 2) > sizeof(r)) { + if (WSNPRINTF(r, sizeof(r), "%s/%s", dirName, out->fName) + >= (int)sizeof(r)) { WLOG(WS_LOG_SFTP, "Path length too large"); WFREE(out->fName, out->heap, DYNTYPE_SFTP); return WS_FATAL_ERROR; } - WSNPRINTF(r, sizeof(r), "%s/%s", dirName, out->fName); if (wolfSSH_RealPath(ssh->sftpDefaultPath, r, s, sizeof(s)) < 0) { WFREE(out->fName, out->heap, DYNTYPE_SFTP);