Skip to content

Commit 0a0341f

Browse files
authored
Merge pull request #880 from LinuxJedi/static-fixes
Static analysis fixes
2 parents 4b46454 + 82b9f11 commit 0a0341f

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

apps/wolfsshd/auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ static int DoCheckUser(const char* usr, WOLFSSHD_AUTH* auth)
10601060
wolfSSH_Log(WS_LOG_INFO, "[SSHD] User ok.");
10611061
ret = WOLFSSH_USERAUTH_SUCCESS;
10621062
}
1063-
else if (ret == WSSHD_AUTH_FAILURE) {
1063+
else if (rc == WSSHD_AUTH_FAILURE) {
10641064
wolfSSH_Log(WS_LOG_INFO, "[SSHD] User %s doesn't exist.", usr);
10651065
ret = WOLFSSH_USERAUTH_INVALID_USER;
10661066
}

src/agent.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,15 +590,15 @@ static int PostRemoveId(WOLFSSH_AGENT_CTX* agent,
590590
int match;
591591

592592
match = WMEMCMP(id, cur->id, WC_SHA256_DIGEST_SIZE);
593-
if (!match) {
593+
if (match) {
594594
prev = cur;
595595
cur = cur->next;
596596
}
597597
else {
598598
if (prev != NULL)
599599
prev->next = cur->next;
600600
else
601-
agent->idList = NULL;
601+
agent->idList = cur->next;
602602

603603
wolfSSH_AGENT_ID_free(cur, agent->heap);
604604
cur = NULL;
@@ -660,7 +660,7 @@ static WOLFSSH_AGENT_ID* FindKeyId(WOLFSSH_AGENT_ID* id,
660660

661661
if (ret == WS_SUCCESS) {
662662
while (id != NULL &&
663-
WMEMCMP(digest, id, WC_SHA256_DIGEST_SIZE) != 0 &&
663+
WMEMCMP(digest, id->id, WC_SHA256_DIGEST_SIZE) != 0 &&
664664
WMEMCMP(keyBlob, id->keyBlob, keyBlobSz)) {
665665
id = id->next;
666666
}

src/internal.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7210,8 +7210,9 @@ static int DoUserAuthRequestRsaCert(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
72107210
}
72117211

72127212
if (ret == WS_SUCCESS) {
7213-
if (publicKeyTypeSz != pk->publicKeyTypeSz &&
7214-
WMEMCMP(publicKeyType, pk->publicKeyType, publicKeyTypeSz) != 0) {
7213+
if (publicKeyTypeSz != pk->publicKeyTypeSz
7214+
|| WMEMCMP(publicKeyType, pk->publicKeyType,
7215+
publicKeyTypeSz) != 0) {
72157216

72167217
WLOG(WS_LOG_DEBUG,
72177218
"Signature's type does not match public key type");
@@ -7309,8 +7310,9 @@ static int DoUserAuthRequestEcc(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
73097310
if (ret == WS_SUCCESS) {
73107311
publicKeyType = pk->publicKey + i;
73117312
i += publicKeyTypeSz;
7312-
if (publicKeyTypeSz != pk->publicKeyTypeSz &&
7313-
WMEMCMP(publicKeyType, pk->publicKeyType, publicKeyTypeSz) != 0) {
7313+
if (publicKeyTypeSz != pk->publicKeyTypeSz
7314+
|| WMEMCMP(publicKeyType, pk->publicKeyType,
7315+
publicKeyTypeSz) != 0) {
73147316

73157317
WLOG(WS_LOG_DEBUG,
73167318
"Public Key's type does not match public key type");
@@ -7351,8 +7353,9 @@ static int DoUserAuthRequestEcc(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
73517353
publicKeyType = pk->signature + i;
73527354
i += publicKeyTypeSz;
73537355

7354-
if (publicKeyTypeSz != pk->publicKeyTypeSz &&
7355-
WMEMCMP(publicKeyType, pk->publicKeyType, publicKeyTypeSz) != 0) {
7356+
if (publicKeyTypeSz != pk->publicKeyTypeSz
7357+
|| WMEMCMP(publicKeyType, pk->publicKeyType,
7358+
publicKeyTypeSz) != 0) {
73567359

73577360
WLOG(WS_LOG_DEBUG,
73587361
"Signature's type does not match public key type");
@@ -7620,7 +7623,7 @@ static int DoUserAuthRequestEd25519(WOLFSSH* ssh,
76207623
publicKeyType = pk->publicKey + i;
76217624
i += publicKeyTypeSz;
76227625
if (publicKeyTypeSz != pk->publicKeyTypeSz
7623-
&& WMEMCMP(publicKeyType,
7626+
|| WMEMCMP(publicKeyType,
76247627
pk->publicKeyType, publicKeyTypeSz) != 0) {
76257628
WLOG(WS_LOG_DEBUG,
76267629
"Public Key's type does not match public key type");
@@ -7651,8 +7654,9 @@ static int DoUserAuthRequestEd25519(WOLFSSH* ssh,
76517654
publicKeyType = pk->signature + i;
76527655
i += publicKeyTypeSz;
76537656

7654-
if (publicKeyTypeSz != pk->publicKeyTypeSz &&
7655-
WMEMCMP(publicKeyType, pk->publicKeyType, publicKeyTypeSz) != 0) {
7657+
if (publicKeyTypeSz != pk->publicKeyTypeSz
7658+
|| WMEMCMP(publicKeyType, pk->publicKeyType,
7659+
publicKeyTypeSz) != 0) {
76567660

76577661
WLOG(WS_LOG_DEBUG,
76587662
"Signature's type does not match public key type");
@@ -8940,7 +8944,7 @@ int wolfSSH_DoModes(const byte* modes, word32 modesSz, int fd)
89408944

89418945
tcgetattr(fd, &term);
89428946

8943-
while (idx < modesSz && modes[idx] != WOLFSSH_TTY_OP_END
8947+
while (idx + TERMINAL_MODE_SZ <= modesSz && modes[idx] != WOLFSSH_TTY_OP_END
89448948
&& modes[idx] < WOLFSSH_TTY_INVALID) {
89458949

89468950
ato32(modes + idx + 1, &arg);

src/ssh.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,12 @@ void wolfSSH_SetTpmDev(WOLFSSH* ssh, WOLFTPM2_DEV* dev)
405405
{
406406
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SetTpmDev()");
407407

408-
if (ssh && ssh->ctx)
408+
if (ssh && ssh->ctx) {
409409
ssh->ctx->tpmDev = dev;
410410

411-
if (ssh->ctx->tpmDev == NULL) {
412-
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmDev: Set tpm dev failed");
411+
if (ssh->ctx->tpmDev == NULL) {
412+
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmDev: Set tpm dev failed");
413+
}
413414
}
414415
}
415416

@@ -418,11 +419,12 @@ void wolfSSH_SetTpmKey(WOLFSSH* ssh, WOLFTPM2_KEY* key)
418419
{
419420
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SetTpmKey()");
420421

421-
if (ssh && ssh->ctx)
422+
if (ssh && ssh->ctx) {
422423
ssh->ctx->tpmKey = key;
423424

424-
if (ssh->ctx->tpmDev == NULL) {
425-
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmKey: Set tpm key failed");
425+
if (ssh->ctx->tpmKey == NULL) {
426+
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmKey: Set tpm key failed");
427+
}
426428
}
427429
}
428430

src/wolfscp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ static int GetScpFileMode(WOLFSSH* ssh, byte* buf, word32 bufSz,
854854

855855
for (i = 0; i < SCP_MODE_OCTET_LEN; i++)
856856
{
857-
if (modeOctet[i] < '0' || modeOctet[0] > '7') {
857+
if (modeOctet[i] < '0' || modeOctet[i] > '7') {
858858
ret = WS_BAD_ARGUMENT;
859859
break;
860860
}

0 commit comments

Comments
 (0)