git://git.exim.org
/
exim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
DKIM: fix base64 decode to ignore whitespace; needed for private-key input
[exim.git]
/
src
/
src
/
base64.c
diff --git
a/src/src/base64.c
b/src/src/base64.c
index f4c4f233b0105fd03547b44edd1cab07cae391a6..61b600f6cec332e5ca5961dc92f7a591c257314b 100644
(file)
--- a/
src/src/base64.c
+++ b/
src/src/base64.c
@@
-134,6
+134,7
@@
Arguments:
Returns: the number of bytes in the result,
or -1 if the input was malformed
Returns: the number of bytes in the result,
or -1 if the input was malformed
+Whitespace in the input is ignored.
A zero is added on to the end to make it easy in cases where the result is to
be interpreted as text. This is not included in the count. */
A zero is added on to the end to make it easy in cases where the result is to
be interpreted as text. This is not included in the count. */
@@
-161,21
+162,29
@@
quantum this may decode to 1, 2, or 3 output bytes. */
while ((x = *code++) != 0)
{
while ((x = *code++) != 0)
{
+ if (isspace(x)) continue;
+
if (x > 127 || (x = dec64table[x]) == 255) return -1;
if (x > 127 || (x = dec64table[x]) == 255) return -1;
- if ((y = *code++) == 0 || (y = dec64table[y]) == 255)
+
+ while (isspace(y = *code++)) ;
+ if (y == 0 || (y = dec64table[y]) == 255)
return -1;
*result++ = (x << 2) | (y >> 4);
return -1;
*result++ = (x << 2) | (y >> 4);
- if ((x = *code++) == '=')
+ while (isspace(x = *code++)) ;
+ if (x == '=')
{
{
- if (*code++ != '=' || *code != 0) return -1;
+ while (isspace(x = *code++)) ;
+ if (x != '=' || *code != 0) return -1;
}
else
{
if (x > 127 || (x = dec64table[x]) == 255) return -1;
*result++ = (y << 4) | (x >> 2);
}
else
{
if (x > 127 || (x = dec64table[x]) == 255) return -1;
*result++ = (y << 4) | (x >> 2);
- if ((y = (*code++)) == '=')
+
+ while (isspace(y = *code++)) ;
+ if (y == '=')
{
if (*code != 0) return -1;
}
{
if (*code != 0) return -1;
}