Skip to content

Commit

Permalink
Release v1.4.15: Release Testing Fixes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ejohnstown committed Dec 22, 2023
1 parent 3feaad9 commit 948b545
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions examples/sftpclient/sftpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 948b545

Please sign in to comment.