1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-08 17:42:09 +03:00

Fix mbedtls_base64_decode() accepting invalid inputs with 4n+1 digits

The last digit was ignored.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2025-06-04 10:33:31 +02:00
parent 683a46e6c1
commit 84999d1a7b
3 changed files with 21 additions and 12 deletions

View File

@@ -183,6 +183,12 @@ int mbedtls_base64_decode(unsigned char *dst, size_t dlen, size_t *olen,
n++;
}
/* In valid base64, the number of digits is always of the form
* 4n, 4n+2 or 4n+3. */
if ((n - equals) % 4 == 1) {
return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
}
if (n == 0) {
*olen = 0;
return 0;