Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base64 fuzz fix/v10 #9227

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# Format:
#
# name {repo} {branch|tag}
libhtp https://github.com/OISF/libhtp 0.5.44
libhtp https://github.com/OISF/libhtp 0.5.45
suricata-update https://github.com/OISF/suricata-update 1.3.0
15 changes: 15 additions & 0 deletions src/util-base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ static inline int GetBase64Value(uint8_t c)
return val;
}

/**
* \brief Checks if the given char in a byte array is Base64 alphabet
*
* \param Char that needs to be checked
*
* \return True if the char was Base64 alphabet, False otherwise
*/
bool IsBase64Alphabet(uint8_t encoded_byte)
{
if (GetBase64Value(encoded_byte) < 0 && encoded_byte != '=') {
return false;
}
return true;
}

/**
* \brief Decodes a 4-byte base64-encoded block into a 3-byte ascii-encoded block
*
Expand Down
1 change: 1 addition & 0 deletions src/util-base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ typedef enum {
/* Function prototypes */
Base64Ecode DecodeBase64(uint8_t *dest, uint32_t dest_size, const uint8_t *src, uint32_t len,
uint32_t *consumed_bytes, uint32_t *decoded_bytes, Base64Mode mode);
bool IsBase64Alphabet(uint8_t encoded_byte);

#endif

Expand Down
7 changes: 4 additions & 3 deletions src/util-decode-mime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,15 +1184,15 @@ static uint32_t ProcessBase64Remainder(

/* Strip spaces in remainder */
for (uint8_t i = 0; i < state->bvr_len; i++) {
if (state->bvremain[i] != ' ') {
if (IsBase64Alphabet(state->bvremain[i])) {
block[cnt++] = state->bvremain[i];
}
}

/* if we don't have 4 bytes see if we can fill it from `buf` */
if (buf && len > 0 && cnt != B64_BLOCK) {
for (uint32_t i = 0; i < len && cnt < B64_BLOCK; i++) {
if (buf[i] != ' ') {
if (IsBase64Alphabet(buf[i])) {
block[cnt++] = buf[i];
}
buf_consumed++;
Expand Down Expand Up @@ -1273,7 +1273,8 @@ static inline MimeDecRetCode ProcessBase64BodyLineCopyRemainder(
return MIME_DEC_ERR_DATA;

for (uint32_t i = offset; i < buf_len; i++) {
if (buf[i] != ' ') {
// Skip any characters outside of the base64 alphabet as per RFC 2045
if (IsBase64Alphabet(buf[i])) {
DEBUG_VALIDATE_BUG_ON(state->bvr_len >= B64_BLOCK);
if (state->bvr_len >= B64_BLOCK)
return MIME_DEC_ERR_DATA;
Expand Down
Loading