1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-28 08:02:54 +00:00

"b64decode -r" did not handle arbitary breaks in base64 encoded

data. White space should be accepted anywhere in a base64 encoded
stream, not just after every chunk (4 characters).

Test-scenario:

VmVsb2NpdHkgUmV3YXJkcw==

and

VmVsb2NpdHkgUmV3YXJkcw
==

should both produce "Velocity Rewards"

PR:		bin/124739
Submitted by:	Mark Andrews <marka@isc.org>
MFC after:	2 weeks
This commit is contained in:
Edwin Groothuis 2010-10-18 05:44:11 +00:00
parent bc15e58058
commit 2d2d15a964
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=214010

View File

@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
#include <netinet/in.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
@ -413,15 +414,40 @@ uu_decode(void)
static int
base64_decode(void)
{
int n;
char inbuf[MAXPATHLEN + 1];
int n, count, count4;
char inbuf[MAXPATHLEN + 1], *p;
unsigned char outbuf[MAXPATHLEN * 4];
char leftover[MAXPATHLEN + 1];
leftover[0] = '\0';
for (;;) {
switch (getline(inbuf, sizeof(inbuf))) {
case 0: return (0);
case 1: return (1);
strcpy(inbuf, leftover);
switch (getline(inbuf + strlen(inbuf),
sizeof(inbuf) - strlen(inbuf))) {
case 0:
return (0);
case 1:
return (1);
}
count = 0;
count4 = -1;
p = inbuf;
while (*p != '\0') {
/*
* Base64 encoded strings have the following
* characters in them: A-Z, a-z, 0-9 and +, / and =
*/
if (isalnum(*p) || *p == '+' || *p == '/' || *p == '=')
count++;
if (count % 4 == 0)
count4 = p - inbuf;
p++;
}
strcpy(leftover, inbuf + count4 + 1);
inbuf[count4 + 1] = 0;
n = b64_pton(inbuf, outbuf, sizeof(outbuf));
if (n < 0)