Skip to content

Commit 3aa9a58

Browse files
committed
move length check before dispatch
1 parent a77e1ff commit 3aa9a58

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

wolfcrypt/src/coding.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,15 @@ static int DoBase64_Encode(const byte* in, word32 inLen, byte* out,
477477

478478
int getSzOnly = (out == NULL);
479479

480-
word32 outSz = (inLen + 3 - 1) / 3 * 4;
481-
word32 addSz = (outSz + BASE64_LINE_SZ - 1) / BASE64_LINE_SZ; /* new lines */
480+
word32 outSz;
481+
word32 addSz;
482482

483483
if (in == NULL && inLen > 0)
484484
return BAD_FUNC_ARG;
485485

486+
outSz = (inLen + 3 - 1) / 3 * 4;
487+
addSz = (outSz + BASE64_LINE_SZ - 1) / BASE64_LINE_SZ; /* new lines */
488+
486489
if (escaped == WC_ESC_NL_ENC)
487490
addSz *= 3; /* instead of just \n, we're doing %0A triplet */
488491
else if (escaped == WC_NO_NL_ENC)

wolfcrypt/src/des3.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,10 @@
17891789
return BAD_FUNC_ARG;
17901790
}
17911791

1792+
if (sz % DES_BLOCK_SIZE != 0) {
1793+
return BAD_LENGTH_E;
1794+
}
1795+
17921796
#ifdef WOLF_CRYPTO_CB
17931797
if (des->devId != INVALID_DEVID) {
17941798
int ret = wc_CryptoCb_Des3Encrypt(des, out, in, sz);
@@ -1819,10 +1823,6 @@
18191823
}
18201824
#endif /* WOLFSSL_ASYNC_CRYPT */
18211825

1822-
if (sz % DES_BLOCK_SIZE != 0) {
1823-
return BAD_LENGTH_E;
1824-
}
1825-
18261826
blocks = sz / DES_BLOCK_SIZE;
18271827
while (blocks--) {
18281828
xorbuf((byte*)des->reg, in, DES_BLOCK_SIZE);
@@ -1844,6 +1844,10 @@
18441844
return BAD_FUNC_ARG;
18451845
}
18461846

1847+
if (sz % DES_BLOCK_SIZE != 0) {
1848+
return BAD_LENGTH_E;
1849+
}
1850+
18471851
#ifdef WOLF_CRYPTO_CB
18481852
if (des->devId != INVALID_DEVID) {
18491853
int ret = wc_CryptoCb_Des3Decrypt(des, out, in, sz);
@@ -1874,10 +1878,6 @@
18741878
}
18751879
#endif /* WOLFSSL_ASYNC_CRYPT */
18761880

1877-
if (sz % DES_BLOCK_SIZE != 0) {
1878-
return BAD_LENGTH_E;
1879-
}
1880-
18811881
blocks = sz / DES_BLOCK_SIZE;
18821882
while (blocks--) {
18831883
XMEMCPY(des->tmp, in, DES_BLOCK_SIZE);

0 commit comments

Comments
 (0)