Skip to content

Commit aaf3e55

Browse files
authored
Merge pull request #908 from LinuxJedi/f-fixes
Static code analysis fixes
2 parents 5272cc4 + 841f050 commit aaf3e55

File tree

7 files changed

+1031
-31
lines changed

7 files changed

+1031
-31
lines changed

src/internal.c

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ const char* GetErrorString(int err)
491491
case WS_KDF_E:
492492
return "KDF error";
493493

494+
case WS_DISCONNECT:
495+
return "peer sent disconnect";
496+
494497
default:
495498
return "Unknown error code";
496499
}
@@ -5758,6 +5761,9 @@ static int KeyAgree_client(WOLFSSH* ssh, byte hashId, const byte* f, word32 fSz)
57585761
}
57595762

57605763

5764+
static INLINE byte SigTypeForId(byte id);
5765+
5766+
57615767
static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
57625768
{
57635769
struct wolfSSH_sigKeyBlock *sigKeyBlock_ptr = NULL;
@@ -6007,9 +6013,10 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
60076013
#ifndef WOLFSSH_NO_RSA
60086014
int tmpIdx = begin - sigSz;
60096015
#endif
6010-
/* Skip past the sig name. Check it, though. Other SSH
6011-
* implementations do the verify based on the name, despite what
6012-
* was agreed upon. XXX*/
6016+
const char* expectedSigName =
6017+
IdToName(SigTypeForId(ssh->handshake->pubKeyId));
6018+
word32 expectedSigNameSz = (word32)WSTRLEN(expectedSigName);
6019+
60136020
begin = 0;
60146021
ret = GetUint32(&scratch, sig, sigSz, &begin);
60156022
if (ret == WS_SUCCESS) {
@@ -6020,6 +6027,16 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
60206027
ret = WS_PARSE_E;
60216028
}
60226029
}
6030+
if (ret == WS_SUCCESS) {
6031+
if (scratch != expectedSigNameSz ||
6032+
WMEMCMP(sig + begin, expectedSigName, scratch) != 0) {
6033+
WLOG(WS_LOG_DEBUG,
6034+
"signature name %.*s did not match negotiated %s",
6035+
(int)scratch, (const char*)(sig + begin),
6036+
expectedSigName);
6037+
ret = WS_PARSE_E;
6038+
}
6039+
}
60236040
if (ret == WS_SUCCESS) {
60246041
begin += scratch;
60256042
ret = GetUint32(&scratch, sig, sigSz, &begin);
@@ -6475,7 +6492,6 @@ static int DoDisconnect(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
64756492
const char* reasonStr = NULL;
64766493
word32 begin = *idx;
64776494

6478-
WOLFSSH_UNUSED(ssh);
64796495
WOLFSSH_UNUSED(len);
64806496
WOLFSSH_UNUSED(reasonStr);
64816497

@@ -6524,7 +6540,8 @@ static int DoDisconnect(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
65246540

65256541
*idx = begin;
65266542

6527-
return WS_SUCCESS;
6543+
ssh->error = WS_DISCONNECT;
6544+
return WS_DISCONNECT;
65286545
}
65296546

65306547

@@ -8629,6 +8646,7 @@ static int DoChannelOpen(WOLFSSH* ssh,
86298646
int isDirect = 0;
86308647
#endif /* WOLFSSH_FWD */
86318648
WOLFSSH_CHANNEL* newChannel = NULL;
8649+
byte channelAppended = 0;
86328650
int ret = WS_SUCCESS;
86338651
word32 fail_reason = OPEN_OK;
86348652

@@ -8723,9 +8741,13 @@ static int DoChannelOpen(WOLFSSH* ssh,
87238741
}
87248742
}
87258743
#endif /* WOLFSSH_FWD */
8726-
ChannelAppend(ssh, newChannel);
8727-
8728-
ssh->clientState = CLIENT_CHANNEL_OPEN_DONE;
8744+
if (ret == WS_SUCCESS) {
8745+
ret = ChannelAppend(ssh, newChannel);
8746+
if (ret == WS_SUCCESS) {
8747+
channelAppended = 1;
8748+
ssh->clientState = CLIENT_CHANNEL_OPEN_DONE;
8749+
}
8750+
}
87298751
}
87308752
}
87318753

@@ -8735,19 +8757,24 @@ static int DoChannelOpen(WOLFSSH* ssh,
87358757
else {
87368758
const char *description = NULL;
87378759

8738-
if (fail_reason == OPEN_ADMINISTRATIVELY_PROHIBITED)
8760+
if (newChannel != NULL && !channelAppended) {
8761+
ChannelDelete(newChannel, ssh->ctx->heap);
8762+
newChannel = NULL;
8763+
}
8764+
8765+
if (fail_reason == OPEN_OK) {
8766+
fail_reason = OPEN_ADMINISTRATIVELY_PROHIBITED;
8767+
description = "Channel open failed.";
8768+
}
8769+
else if (fail_reason == OPEN_ADMINISTRATIVELY_PROHIBITED)
87398770
description = "Administratively prohibited.";
87408771
else if (fail_reason == OPEN_UNKNOWN_CHANNEL_TYPE)
87418772
description = "Channel type not supported.";
87428773
else if (fail_reason == OPEN_RESOURCE_SHORTAGE)
87438774
description = "Not enough resources.";
87448775

8745-
if (description != NULL) {
8746-
ret = SendChannelOpenFail(ssh, peerChannelId,
8747-
fail_reason, description, "en");
8748-
}
8749-
else
8750-
ret = SendRequestSuccess(ssh, 0); /* XXX Is this right? */
8776+
ret = SendChannelOpenFail(ssh, peerChannelId,
8777+
fail_reason, description, "en");
87518778
}
87528779

87538780
#ifdef WOLFSSH_FWD
@@ -10594,7 +10621,6 @@ static int PreparePacket(WOLFSSH* ssh, word32 payloadSz)
1059410621
return ret;
1059510622
}
1059610623

10597-
1059810624
static int BundlePacket(WOLFSSH* ssh)
1059910625
{
1060010626
byte* output = NULL;
@@ -17563,7 +17589,7 @@ int wolfSSH_oct2dec(WOLFSSH* ssh, byte* oct, word32 octSz)
1756317589

1756417590
for (i = 0; i < octSz; i++)
1756517591
{
17566-
if (oct[i] < '0' || oct[0] > '7') {
17592+
if (oct[i] < '0' || oct[i] > '7') {
1756717593
ret = WS_BAD_ARGUMENT;
1756817594
break;
1756917595
}

src/keygen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ int wolfSSH_MakeEcdsaKey(byte* out, word32 outSz, word32 size)
189189

190190
int wolfSSH_MakeEd25519Key(byte* out, word32 outSz, word32 size)
191191
{
192-
#ifndef WOLFSSH_NO_ED25519
192+
#if !defined(WOLFSSH_NO_ED25519) && defined(HAVE_ED25519) && \
193+
defined(HAVE_ED25519_MAKE_KEY) && defined(HAVE_ED25519_KEY_EXPORT)
193194

194195
int ret = WS_SUCCESS;
195196
WC_RNG rng;

src/wolfsftp.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4515,8 +4515,8 @@ int SFTP_RemoveHandleNode(WOLFSSH* ssh, byte* handle, word32 handleSz)
45154515
cur->prev->next = cur->next;
45164516
}
45174517

4518-
if (cur->next == NULL && cur->prev == NULL) {
4519-
ssh->handleList = NULL;
4518+
if (cur == ssh->handleList) {
4519+
ssh->handleList = cur->next;
45204520
}
45214521

45224522
WFREE(cur, ssh->ctx->heap, DYNTYPE_SFTP);
@@ -4570,8 +4570,8 @@ static int SFTP_FreeHandles(WOLFSSH* ssh)
45704570
/* mktime() expects month from 0 to 11. Nucleus months
45714571
* are saved as 1 to 12. Hence 1 is being deducted to
45724572
* make it compatible with Unix time stamp. */
4573-
#define WS_GETMON(d) (_GETMON(d) - 5)
4574-
#define WS_GETHOUR(t) (_GETHOUR(t) - 1)
4573+
#define WS_GETMON(d) (_GETMON(d) - 1)
4574+
#define WS_GETHOUR(t) _GETHOUR(t)
45754575
#else
45764576
#define WS_GETMON(d) _GETMON(d)
45774577
#define WS_GETHOUR(t) _GETHOUR(t)
@@ -4592,6 +4592,13 @@ static word32 TimeTo32(word16 d, word16 t)
45924592

45934593
return mktime(&tmp);
45944594
}
4595+
4596+
#ifdef WOLFSSH_TEST_INTERNAL
4597+
int wolfSSH_TestNucleusMonthFromDate(word16 d)
4598+
{
4599+
return (int)WS_GETMON(d);
4600+
}
4601+
#endif
45954602
#endif /* NO_WOLFSSH_MKTIME */
45964603

45974604

0 commit comments

Comments
 (0)