Skip to content

Commit

Permalink
Do the length check first to avoid reading past the buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
d0k committed Jul 17, 2010
1 parent 56df759 commit 5251998
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base64.cc
Expand Up @@ -110,9 +110,9 @@ char *base64_decode(const unsigned char *str, int length, int *ret_length)
exit(1);
}

while ((ch = *current++) != '\0' && length-- > 0) {
while (length-- > 0 && (ch = *current++) != '\0') {
if (ch == base64_pad) {
if (*current != '=' && (i % 4) == 1) {
if ((i % 4) == 1 && *current != '=') {
free(result);
return NULL;
}
Expand Down

0 comments on commit 5251998

Please sign in to comment.