summaryrefslogtreecommitdiffstats
path: root/usr.bin/uudecode
diff options
context:
space:
mode:
authoredwin <edwin@FreeBSD.org>2010-10-18 05:44:11 +0000
committeredwin <edwin@FreeBSD.org>2010-10-18 05:44:11 +0000
commite2471b32d60f51b890f122148089b479b9cfc13f (patch)
tree7d386db88cbceb66409a24ac1eddcdb81bcfecbb /usr.bin/uudecode
parent92672df66c790abee9d5fbba2f3af2ac1461e892 (diff)
downloadFreeBSD-src-e2471b32d60f51b890f122148089b479b9cfc13f.zip
FreeBSD-src-e2471b32d60f51b890f122148089b479b9cfc13f.tar.gz
"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
Diffstat (limited to 'usr.bin/uudecode')
-rw-r--r--usr.bin/uudecode/uudecode.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/usr.bin/uudecode/uudecode.c b/usr.bin/uudecode/uudecode.c
index 9217dd9..58c0878 100644
--- a/usr.bin/uudecode/uudecode.c
+++ b/usr.bin/uudecode/uudecode.c
@@ -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)
OpenPOWER on IntegriCloud