Skip to content

Commit 4ebb6be

Browse files
authored
Merge pull request #998 from ejohnstown/sf7
Static Analysis Fixes
2 parents 0f11691 + caec20f commit 4ebb6be

3 files changed

Lines changed: 100 additions & 26 deletions

File tree

src/internal.c

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4423,13 +4423,15 @@ static int DoKexInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
44234423
}
44244424
/* Extension Info Flag */
44254425
if (ret == WS_SUCCESS) {
4426-
/* Only checking for this is we are server. Our client does
4427-
* not have anything to say to a server, yet. */
4428-
if (side == WOLFSSH_ENDPOINT_SERVER && !ssh->extInfoSent) {
4426+
/* Determine whether we should send EXT_INFO after NEWKEYS based on
4427+
* whether the peer advertised ext-info-c (server) or ext-info-s
4428+
* (client). */
4429+
if (!ssh->extInfoSent) {
44294430
byte extInfo;
44304431

4431-
/* Match the client accepts extInfo. */
4432-
algoId = ID_EXTINFO_C;
4432+
/* Match the peer accepts extInfo. */
4433+
algoId = (side == WOLFSSH_ENDPOINT_SERVER)
4434+
? ID_EXTINFO_C : ID_EXTINFO_S;
44334435
extInfo = MatchIdLists(side, list, listSz, &algoId, 1);
44344436
ssh->sendExtInfo = extInfo == algoId;
44354437
}
@@ -11314,6 +11316,10 @@ int SendKexInit(WOLFSSH* ssh)
1131411316
kexAlgoNamesPlus = ",ext-info-c";
1131511317
kexAlgoNamesPlusSz = (word32)WSTRLEN(kexAlgoNamesPlus);
1131611318
}
11319+
else {
11320+
kexAlgoNamesPlus = ",ext-info-s";
11321+
kexAlgoNamesPlusSz = (word32)WSTRLEN(kexAlgoNamesPlus);
11322+
}
1131711323

1131811324
kexAlgoNamesSz = AlgoListSz(ssh->algoListKex);
1131911325
encAlgoNamesSz = AlgoListSz(ssh->algoListCipher);
@@ -14207,19 +14213,16 @@ int SendServiceAccept(WOLFSSH* ssh, byte serviceId)
1420714213
static const char serverSigAlgsName[] = "server-sig-algs";
1420814214

1420914215

14210-
int SendExtInfo(WOLFSSH* ssh)
14216+
#ifndef NO_WOLFSSH_SERVER
14217+
static int SendExtInfoServer(WOLFSSH* ssh)
1421114218
{
1421214219
byte* output;
1421314220
word32 idx;
1421414221
word32 keyAlgoNamesSz = 0;
1421514222
word32 serverSigAlgsNameSz = 0;
1421614223
int ret = WS_SUCCESS;
1421714224

14218-
WLOG(WS_LOG_DEBUG, "Entering SendExtInfo()");
14219-
14220-
if (ssh == NULL) {
14221-
ret = WS_BAD_ARGUMENT;
14222-
}
14225+
WLOG(WS_LOG_DEBUG, "Entering SendExtInfoServer()");
1422314226

1422414227
if (ret == WS_SUCCESS) {
1422514228
keyAlgoNamesSz = AlgoListSz(ssh->algoListKeyAccepted);
@@ -14259,6 +14262,51 @@ int SendExtInfo(WOLFSSH* ssh)
1425914262
ret = wolfSSH_SendPacket(ssh);
1426014263
}
1426114264

14265+
WLOG(WS_LOG_DEBUG, "Leaving SendExtInfoServer(), ret = %d", ret);
14266+
return ret;
14267+
}
14268+
#endif /* NO_WOLFSSH_SERVER */
14269+
14270+
14271+
#ifndef NO_WOLFSSH_CLIENT
14272+
static int SendExtInfoClient(WOLFSSH* ssh)
14273+
{
14274+
int ret = WS_SUCCESS;
14275+
14276+
WOLFSSH_UNUSED(ssh);
14277+
WLOG(WS_LOG_DEBUG, "Entering SendExtInfoClient()");
14278+
/* This is currently a stub. Our client doesn't have anything to say. */
14279+
WLOG(WS_LOG_DEBUG, "Leaving SendExtInfoClient(), ret = %d", ret);
14280+
14281+
return ret;
14282+
}
14283+
#endif /* NO_WOLFSSH_CLIENT */
14284+
14285+
14286+
int SendExtInfo(WOLFSSH* ssh)
14287+
{
14288+
int ret = WS_SUCCESS;
14289+
14290+
WLOG(WS_LOG_DEBUG, "Entering SendExtInfo()");
14291+
14292+
if (ssh == NULL || ssh->ctx == NULL) {
14293+
ret = WS_BAD_ARGUMENT;
14294+
}
14295+
14296+
if (ret == WS_SUCCESS) {
14297+
/* Disabling server and client is checked at compile time. */
14298+
#ifndef NO_WOLFSSH_SERVER
14299+
if (ssh->ctx->side == WOLFSSH_ENDPOINT_SERVER) {
14300+
ret = SendExtInfoServer(ssh);
14301+
}
14302+
#endif
14303+
#ifndef NO_WOLFSSH_CLIENT
14304+
if (ssh->ctx->side == WOLFSSH_ENDPOINT_CLIENT) {
14305+
ret = SendExtInfoClient(ssh);
14306+
}
14307+
#endif
14308+
}
14309+
1426214310
WLOG(WS_LOG_DEBUG, "Leaving SendExtInfo(), ret = %d", ret);
1426314311
return ret;
1426414312
}

src/wolfsftp.c

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3811,20 +3811,46 @@ int wolfSSH_SFTP_RecvWrite(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
38113811
return WS_BUFFER_E;
38123812
}
38133813

3814-
ret = WPWRITE(ssh->fs, fd, (byte*)str, strSz, ofst);
3815-
if (ret < 0) {
3816-
#if defined(WOLFSSL_NUCLEUS) && defined(DEBUG_WOLFSSH)
3817-
if (ret == NUF_NOSPC) {
3818-
WLOG(WS_LOG_SFTP, "Ran out of memory");
3814+
{
3815+
word32 written = 0;
3816+
3817+
/* Retry while WPWRITE makes forward progress; bail on error
3818+
* or zero return to avoid spinning on a stuck backend. */
3819+
while (written < strSz) {
3820+
ret = WPWRITE(ssh->fs, fd, (byte*)str + written,
3821+
strSz - written, ofst);
3822+
if (ret <= 0) {
3823+
break;
3824+
}
3825+
written += (word32)ret;
3826+
/* Advance the split 64-bit offset, propagating carry. */
3827+
ofst[0] += (word32)ret;
3828+
if (ofst[0] < (word32)ret) {
3829+
ofst[1] += 1;
3830+
}
3831+
}
3832+
3833+
if (ret < 0) {
3834+
#if defined(WOLFSSL_NUCLEUS) && defined(DEBUG_WOLFSSH)
3835+
if (ret == NUF_NOSPC) {
3836+
WLOG(WS_LOG_SFTP, "Ran out of memory");
3837+
}
3838+
#endif
3839+
WLOG(WS_LOG_SFTP, "Error writing to file");
3840+
res = err;
3841+
type = WOLFSSH_FTP_FAILURE;
3842+
ret = WS_INVALID_STATE_E;
3843+
}
3844+
else if (written != strSz) {
3845+
WLOG(WS_LOG_SFTP, "Short write: %u of %u bytes",
3846+
written, strSz);
3847+
res = err;
3848+
type = WOLFSSH_FTP_FAILURE;
3849+
ret = WS_INVALID_STATE_E;
3850+
}
3851+
else {
3852+
ret = WS_SUCCESS;
38193853
}
3820-
#endif
3821-
WLOG(WS_LOG_SFTP, "Error writing to file");
3822-
res = err;
3823-
type = WOLFSSH_FTP_FAILURE;
3824-
ret = WS_INVALID_STATE_E;
3825-
}
3826-
else {
3827-
ret = WS_SUCCESS;
38283854
}
38293855
}
38303856

wolfssh/port.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ extern "C" {
11271127
fseek(fd, ofst, 0);
11281128
}
11291129

1130-
return fwrite(buf, sz, 1, fd);
1130+
return fwrite(buf, sizeof(unsigned char), sz, fd);
11311131
}
11321132
#define WPWRITE(fs,fd,b,s,o) wPwrite((fd),(b),(s),(o))
11331133
#endif
@@ -1143,7 +1143,7 @@ extern "C" {
11431143
fseek(fd, ofst, 0);
11441144
}
11451145

1146-
return fread(buf, 1, sz, fd);
1146+
return fread(buf, sizeof(unsigned char), sz, fd);
11471147
}
11481148
#define WPREAD(fs,fd,b,s,o) wPread((fd),(b),(s),(o))
11491149
#endif

0 commit comments

Comments
 (0)