aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/suricata/src/util-base64.c
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/suricata/src/util-base64.c')
-rw-r--r--framework/src/suricata/src/util-base64.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/framework/src/suricata/src/util-base64.c b/framework/src/suricata/src/util-base64.c
index f4b508a0..bea92d52 100644
--- a/framework/src/suricata/src/util-base64.c
+++ b/framework/src/suricata/src/util-base64.c
@@ -50,8 +50,8 @@ static const int b64table[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
*
* \return The decoded value (0 or above), or -1 if the parameter is invalid
*/
-static inline int GetBase64Value(uint8_t c) {
-
+static inline int GetBase64Value(uint8_t c)
+{
int val = -1;
/* Pull from conversion table */
@@ -70,8 +70,8 @@ static inline int GetBase64Value(uint8_t c) {
*
* \return none
*/
-static inline void DecodeBase64Block(uint8_t ascii[ASCII_BLOCK], uint8_t b64[B64_BLOCK]) {
-
+static inline void DecodeBase64Block(uint8_t ascii[ASCII_BLOCK], uint8_t b64[B64_BLOCK])
+{
ascii[0] = (uint8_t) (b64[0] << 2) | (b64[1] >> 4);
ascii[1] = (uint8_t) (b64[1] << 4) | (b64[2] >> 2);
ascii[2] = (uint8_t) (b64[2] << 6) | (b64[3]);
@@ -83,11 +83,14 @@ static inline void DecodeBase64Block(uint8_t ascii[ASCII_BLOCK], uint8_t b64[B64
* \param dest The destination byte buffer
* \param src The source string
* \param len The length of the source string
+ * \param strict If set file on invalid byte, otherwise return what has been
+ * decoded.
*
* \return Number of bytes decoded, or 0 if no data is decoded or it fails
*/
-uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len) {
-
+uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len,
+ int strict)
+{
int val;
uint32_t padding = 0, numDecoded = 0, bbidx = 0, valid = 1, i;
uint8_t *dptr = dest;
@@ -103,7 +106,9 @@ uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len) {
/* Invalid character found, so decoding fails */
if (src[i] != '=') {
valid = 0;
- numDecoded = 0;
+ if (strict) {
+ numDecoded = 0;
+ }
break;
}
padding++;