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.
pull/635/head
John Safranek 2023-12-22 14:43:34 -08:00
parent 3feaad95af
commit 948b545ad8
No known key found for this signature in database
GPG Key ID: 8CE817DE0D3CCB4A
2 changed files with 21 additions and 21 deletions

View File

@ -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;

View File

@ -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);