Date: Mon, 18 Oct 2010 05:44:11 +0000 (UTC) From: Edwin Groothuis <edwin@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r214010 - head/usr.bin/uudecode Message-ID: <201010180544.o9I5iBqi085940@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: edwin Date: Mon Oct 18 05:44:11 2010 New Revision: 214010 URL: http://svn.freebsd.org/changeset/base/214010 Log: "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 Modified: head/usr.bin/uudecode/uudecode.c Modified: head/usr.bin/uudecode/uudecode.c ============================================================================== --- head/usr.bin/uudecode/uudecode.c Mon Oct 18 05:16:44 2010 (r214009) +++ head/usr.bin/uudecode/uudecode.c Mon Oct 18 05:44:11 2010 (r214010) @@ -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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201010180544.o9I5iBqi085940>