From owner-svn-src-all@FreeBSD.ORG Mon Oct 18 05:44:12 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1FDBC10656A3; Mon, 18 Oct 2010 05:44:12 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0E0858FC14; Mon, 18 Oct 2010 05:44:12 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o9I5iBtd085942; Mon, 18 Oct 2010 05:44:11 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o9I5iBqi085940; Mon, 18 Oct 2010 05:44:11 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <201010180544.o9I5iBqi085940@svn.freebsd.org> From: Edwin Groothuis Date: Mon, 18 Oct 2010 05:44:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r214010 - head/usr.bin/uudecode X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Oct 2010 05:44:12 -0000 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 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 +#include #include #include #include @@ -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)