Skip to content

Commit ef6b6c5

Browse files
Merge pull request #870 from ejohnstown/cov-untrusted-divisor
Coverity: Untrusted divisor
2 parents fb92a35 + 3f8a1b8 commit ef6b6c5

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/internal.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4757,7 +4757,7 @@ static int DoKexDhInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
47574757
* in the message isn't of the DH e value. Treat the Q as e. */
47584758
/* DYNTYPE_DH */
47594759

4760-
byte* e;
4760+
const byte* e;
47614761
word32 eSz;
47624762
word32 begin;
47634763
int ret = WS_SUCCESS;
@@ -4776,28 +4776,20 @@ static int DoKexDhInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
47764776
*idx += len;
47774777
return WS_SUCCESS;
47784778
}
4779-
}
47804779

4781-
if (ret == WS_SUCCESS) {
47824780
begin = *idx;
4783-
ret = GetUint32(&eSz, buf, len, &begin);
4781+
ret = GetStringRef(&eSz, &e, buf, len, &begin);
47844782
}
47854783

47864784
if (ret == WS_SUCCESS) {
47874785
/* Validate eSz */
4788-
if ((len < begin) || (eSz > len - begin)) {
4789-
ret = WS_RECV_OVERFLOW_E;
4790-
}
4786+
if (eSz > (word32)sizeof(ssh->handshake->e) || eSz == 0)
4787+
ret = WS_PUBKEY_REJECTED_E;
47914788
}
47924789

47934790
if (ret == WS_SUCCESS) {
4794-
e = buf + begin;
4795-
begin += eSz;
4796-
4797-
if (eSz <= (word32)sizeof(ssh->handshake->e)) {
4798-
WMEMCPY(ssh->handshake->e, e, eSz);
4799-
ssh->handshake->eSz = eSz;
4800-
}
4791+
WMEMCPY(ssh->handshake->e, e, eSz);
4792+
ssh->handshake->eSz = eSz;
48014793

48024794
ssh->clientState = CLIENT_KEXDH_INIT_DONE;
48034795
*idx = begin;

src/misc.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,17 @@ STATIC INLINE word32 min(word32 a, word32 b)
7474
/* convert opaque to 32 bit integer */
7575
STATIC INLINE void ato32(const byte* c, word32* u32)
7676
{
77-
*u32 = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3];
77+
word32 v = 0;
78+
79+
v |= (word32)(c[0] & 0xFF);
80+
v <<= 8;
81+
v |= (word32)(c[1] & 0xFF);
82+
v <<= 8;
83+
v |= (word32)(c[2] & 0xFF);
84+
v <<= 8;
85+
v |= (word32)(c[3] & 0xFF);
86+
87+
*u32 = v;
7888
}
7989

8090

0 commit comments

Comments
 (0)