From marka@isc.org  Thu Jun 19 00:27:50 2008
Return-Path: <marka@isc.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id BDBF11065712
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 19 Jun 2008 00:27:50 +0000 (UTC)
	(envelope-from marka@isc.org)
Received: from drugs.dv.isc.org (drugs.dv.isc.org [IPv6:2001:470:1f00:820:214:22ff:fed9:fbdc])
	by mx1.freebsd.org (Postfix) with ESMTP id 845338FC1A
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 19 Jun 2008 00:27:50 +0000 (UTC)
	(envelope-from marka@isc.org)
Received: from drugs.dv.isc.org (localhost [127.0.0.1])
	by drugs.dv.isc.org (8.14.2/8.14.2) with ESMTP id m5J0RnDQ006891
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 19 Jun 2008 10:27:49 +1000 (EST)
	(envelope-from marka@drugs.dv.isc.org)
Received: (from marka@localhost)
	by drugs.dv.isc.org (8.14.2/8.14.2/Submit) id m5J0Rmbn006890;
	Thu, 19 Jun 2008 10:27:48 +1000 (EST)
	(envelope-from marka)
Message-Id: <200806190027.m5J0Rmbn006890@drugs.dv.isc.org>
Date: Thu, 19 Jun 2008 10:27:48 +1000 (EST)
From: Mark Andrews <marka@isc.org>
Reply-To: Mark Andrews <marka@isc.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: "b64decode -r" fails to decode legal base64 encoded data
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         124739
>Category:       bin
>Synopsis:       b64decode(1): "b64decode -r" fails to decode legal base64 encoded data
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    edwin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 19 00:30:34 UTC 2008
>Closed-Date:    Wed Nov 03 10:12:38 UTC 2010
>Last-Modified:  Wed Nov  3 10:20:10 UTC 2010
>Originator:     Mark Andrews
>Release:        FreeBSD 6.3-STABLE i386
>Organization:
ISC
>Environment:
System: FreeBSD drugs.dv.isc.org 6.3-STABLE FreeBSD 6.3-STABLE #19: Fri Apr 25 13:07:00 EST 2008 marka@drugs.dv.isc.org:/usr/obj/usr/src/sys/DRUGS i386


>Description:

	"b64decode -r" doesn't 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).

>How-To-Repeat:

	Enter the string "VmVsb2NpdHkgUmV3YXJkcw==" with and without
	the "==" on the first line.

	% b64decode -r
	VmVsb2NpdHkgUmV3YXJkcw
	b64decode: stdin: /dev/stdout: error decoding base64 input stream
	% b64decode -r
	VmVsb2NpdHkgUmV3YXJkcw==
	Velocity Rewards
	% 

>Fix:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Wed Aug 6 07:49:34 UTC 2008 
Responsible-Changed-Why:  
Track, grab, munch, fix. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=124739 

From: Edwin Groothuis <edwin@freebsd.org>
To: FreeBSD Gnats Submit <freebsd-gnats-submit@freebsd.org>
Cc:  
Subject: Re: bin/124739: b64decode(1): "b64decode -r" fails to decode legal base64 encoded data
Date: Wed, 6 Aug 2008 17:48:35 +1000

 --+QahgC5+KEYLbs62
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 See patch, please check if it works as you expected.
 It's a style patch and a your-problem-patch in one go, but the idea
 is there.
 
 -- 
 Edwin Groothuis
 edwin@freebsd.org
 http://www.mavetju.org
 
 --+QahgC5+KEYLbs62
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=a
 
 Index: uudecode.c
 ===================================================================
 --- uudecode.c	(revision 181341)
 +++ uudecode.c	(working copy)
 @@ -57,6 +57,7 @@
  
  #include <netinet/in.h>
  
 +#include <ctype.h>
  #include <err.h>
  #include <errno.h>
  #include <fcntl.h>
 @@ -87,7 +88,7 @@
  		base64 = 1;
  
  	while ((ch = getopt(argc, argv, "cimo:prs")) != -1) {
 -		switch(ch) {
 +		switch (ch) {
  		case 'c':
  			if (oflag || rflag)
  				usage();
 @@ -125,10 +126,10 @@
  			usage();
  		}
  	}
 -        argc -= optind;
 -        argv += optind;
 +	argc -= optind;
 +	argv += optind;
  
 -	if (*argv) {
 +	if (*argv != NULL) {
  		rval = 0;
  		do {
  			infp = fopen(infile = *argv, "r");
 @@ -184,7 +185,7 @@
  	void *handle;
  	struct passwd *pw;
  	struct stat st;
 -	char buf[MAXPATHLEN+1];
 +	char buf[MAXPATHLEN + 1];
  
  	base64 = 0;
  	/* search for header line */
 @@ -206,7 +207,7 @@
  		*q++ = '\0';
  		/* q points to filename */
  		n = strlen(q);
 -		while (n > 0 && (q[n-1] == '\n' || q[n-1] == '\r'))
 +		while (n > 0 && (q[n - 1] == '\n' || q[n - 1] == '\r'))
  			q[--n] = '\0';
  		/* found valid header? */
  		if (n > 0)
 @@ -259,7 +260,7 @@
  	if (pflag || strcmp(outfile, "/dev/stdout") == 0)
  		outfp = stdout;
  	else {
 -		flags = O_WRONLY|O_CREAT|O_EXCL;
 +		flags = O_WRONLY | O_CREAT | O_EXCL;
  		if (lstat(outfile, &st) == 0) {
  			if (iflag) {
  				warnc(EEXIST, "%s: %s", infile, outfile);
 @@ -305,6 +306,7 @@
  static int
  getline(char *buf, size_t size)
  {
 +
  	if (fgets(buf, size, infp) != NULL)
  		return (2);
  	if (rflag)
 @@ -336,22 +338,24 @@
  {
  	int i, ch;
  	char *p;
 -	char buf[MAXPATHLEN+1];
 +	char buf[MAXPATHLEN + 1];
  
  	/* for each input line */
  	for (;;) {
  		switch (getline(buf, sizeof(buf))) {
 -		case 0: return (0);
 -		case 1: return (1);
 +		case 0:
 +			return (0);
 +		case 1:
 +			return (1);
  		}
  
 -#define	DEC(c)	(((c) - ' ') & 077)		/* single character decode */
 -#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
 +#define	DEC(c)		(((c) - ' ') & 077)	/* single character decode */
 +#define	IS_DEC(c)	( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
  
 -#define OUT_OF_RANGE do {						\
 +#define	OUT_OF_RANGE	do {						\
  	warnx("%s: %s: character out of range: [%d-%d]",		\
  	    infile, outfile, 1 + ' ', 077 + ' ' + 1);			\
 -        return (1);							\
 +	return (1);							\
  } while (0)
  
  		/*
 @@ -364,8 +368,8 @@
  		for (++p; i > 0; p += 4, i -= 3)
  			if (i >= 3) {
  				if (!(IS_DEC(*p) && IS_DEC(*(p + 1)) &&
 -				     IS_DEC(*(p + 2)) && IS_DEC(*(p + 3))))
 -                                	OUT_OF_RANGE;
 +				    IS_DEC(*(p + 2)) && IS_DEC(*(p + 3))))
 +					OUT_OF_RANGE;
  
  				ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
  				putc(ch, outfp);
 @@ -373,66 +377,94 @@
  				putc(ch, outfp);
  				ch = DEC(p[2]) << 6 | DEC(p[3]);
  				putc(ch, outfp);
 -			}
 -			else {
 +			} else {
  				if (i >= 1) {
  					if (!(IS_DEC(*p) && IS_DEC(*(p + 1))))
 -	                                	OUT_OF_RANGE;
 +						OUT_OF_RANGE;
  					ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
  					putc(ch, outfp);
  				}
  				if (i >= 2) {
  					if (!(IS_DEC(*(p + 1)) &&
 -						IS_DEC(*(p + 2))))
 -		                                OUT_OF_RANGE;
 +					    IS_DEC(*(p + 2))))
 +						OUT_OF_RANGE;
  
  					ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
  					putc(ch, outfp);
  				}
  				if (i >= 3) {
  					if (!(IS_DEC(*(p + 2)) &&
 -						IS_DEC(*(p + 3))))
 -		                                OUT_OF_RANGE;
 +					    IS_DEC(*(p + 3))))
 +						OUT_OF_RANGE;
  					ch = DEC(p[2]) << 6 | DEC(p[3]);
  					putc(ch, outfp);
  				}
  			}
  	}
  	switch (getline(buf, sizeof(buf))) {
 -	case 0:  return (0);
 -	case 1:  return (1);
 -	default: return (checkend(buf, "end", "no \"end\" line"));
 +	case 0:
 +		return (0);
 +	case 1:
 +		return (1);
 +	default:
 +		return (checkend(buf, "end", "no \"end\" line"));
  	}
  }
  
  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)
  			break;
  		fwrite(outbuf, 1, n, outfp);
  	}
 -	return (checkend(inbuf, "====",
 -		    "error decoding base64 input stream"));
 +	return (checkend(inbuf, "====", "error decoding base64 input stream"));
  }
  
  static void
  usage(void)
  {
 -	(void)fprintf(stderr,
 -"usage: uudecode [-cimprs] [file ...]\n"
 -"       uudecode [-i] -o output_file [file]\n"
 -"       b64decode [-cimprs] [file ...]\n"
 -"       b64decode [-i] -o output_file [file]\n");
 +
 +	fprintf(stderr,
 +	    "usage: uudecode [-cimprs] [file ...]\n"
 +	    "       uudecode [-i] -o output_file [file]\n"
 +	    "       b64decode [-cimprs] [file ...]\n"
 +	    "       b64decode [-i] -o output_file [file]\n");
  	exit(1);
  }
 
 --+QahgC5+KEYLbs62--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/124739: commit references a PR
Date: Mon, 18 Oct 2010 04:00:22 +0000 (UTC)

 Author: edwin
 Date: Mon Oct 18 03:59:55 2010
 New Revision: 214002
 URL: http://svn.freebsd.org/changeset/base/214002
 
 Log:
   Stylify of uudecode(1)
   Part of PR bin/124739.
   
   PR:		bin/124739
   Submitted by:	Mark Andrews <marka@isc.org>
 
 Modified:
   head/usr.bin/uudecode/uudecode.c
 
 Modified: head/usr.bin/uudecode/uudecode.c
 ==============================================================================
 --- head/usr.bin/uudecode/uudecode.c	Mon Oct 18 03:34:33 2010	(r214001)
 +++ head/usr.bin/uudecode/uudecode.c	Mon Oct 18 03:59:55 2010	(r214002)
 @@ -87,7 +87,7 @@ main(int argc, char *argv[])
  		base64 = 1;
  
  	while ((ch = getopt(argc, argv, "cimo:prs")) != -1) {
 -		switch(ch) {
 +		switch (ch) {
  		case 'c':
  			if (oflag || rflag)
  				usage();
 @@ -125,10 +125,10 @@ main(int argc, char *argv[])
  			usage();
  		}
  	}
 -        argc -= optind;
 -        argv += optind;
 +	argc -= optind;
 +	argv += optind;
  
 -	if (*argv) {
 +	if (*argv != NULL) {
  		rval = 0;
  		do {
  			infp = fopen(infile = *argv, "r");
 @@ -184,7 +184,7 @@ decode2(void)
  	void *handle;
  	struct passwd *pw;
  	struct stat st;
 -	char buf[MAXPATHLEN+1];
 +	char buf[MAXPATHLEN + 1];
  
  	base64 = 0;
  	/* search for header line */
 @@ -259,7 +259,7 @@ decode2(void)
  	if (pflag || strcmp(outfile, "/dev/stdout") == 0)
  		outfp = stdout;
  	else {
 -		flags = O_WRONLY|O_CREAT|O_EXCL;
 +		flags = O_WRONLY | O_CREAT | O_EXCL;
  		if (lstat(outfile, &st) == 0) {
  			if (iflag) {
  				warnc(EEXIST, "%s: %s", infile, outfile);
 @@ -305,6 +305,7 @@ decode2(void)
  static int
  getline(char *buf, size_t size)
  {
 +
  	if (fgets(buf, size, infp) != NULL)
  		return (2);
  	if (rflag)
 @@ -341,17 +342,19 @@ uu_decode(void)
  	/* for each input line */
  	for (;;) {
  		switch (getline(buf, sizeof(buf))) {
 -		case 0: return (0);
 -		case 1: return (1);
 +		case 0:
 +			return (0);
 +		case 1:
 +			return (1);
  		}
  
 -#define	DEC(c)	(((c) - ' ') & 077)		/* single character decode */
 -#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
 +#define	DEC(c)		(((c) - ' ') & 077)	/* single character decode */
 +#define IS_DEC(c)	 ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
  
  #define OUT_OF_RANGE do {						\
  	warnx("%s: %s: character out of range: [%d-%d]",		\
  	    infile, outfile, 1 + ' ', 077 + ' ' + 1);			\
 -        return (1);							\
 +	return (1);							\
  } while (0)
  
  		/*
 @@ -364,8 +367,8 @@ uu_decode(void)
  		for (++p; i > 0; p += 4, i -= 3)
  			if (i >= 3) {
  				if (!(IS_DEC(*p) && IS_DEC(*(p + 1)) &&
 -				     IS_DEC(*(p + 2)) && IS_DEC(*(p + 3))))
 -                                	OUT_OF_RANGE;
 +				    IS_DEC(*(p + 2)) && IS_DEC(*(p + 3))))
 +					OUT_OF_RANGE;
  
  				ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
  				putc(ch, outfp);
 @@ -373,8 +376,7 @@ uu_decode(void)
  				putc(ch, outfp);
  				ch = DEC(p[2]) << 6 | DEC(p[3]);
  				putc(ch, outfp);
 -			}
 -			else {
 +			} else {
  				if (i >= 1) {
  					if (!(IS_DEC(*p) && IS_DEC(*(p + 1))))
  	                                	OUT_OF_RANGE;
 @@ -383,25 +385,28 @@ uu_decode(void)
  				}
  				if (i >= 2) {
  					if (!(IS_DEC(*(p + 1)) &&
 -						IS_DEC(*(p + 2))))
 -		                                OUT_OF_RANGE;
 +					    IS_DEC(*(p + 2))))
 +						OUT_OF_RANGE;
  
  					ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
  					putc(ch, outfp);
  				}
  				if (i >= 3) {
  					if (!(IS_DEC(*(p + 2)) &&
 -						IS_DEC(*(p + 3))))
 -		                                OUT_OF_RANGE;
 +					    IS_DEC(*(p + 3))))
 +						OUT_OF_RANGE;
  					ch = DEC(p[2]) << 6 | DEC(p[3]);
  					putc(ch, outfp);
  				}
  			}
  	}
  	switch (getline(buf, sizeof(buf))) {
 -	case 0:  return (0);
 -	case 1:  return (1);
 -	default: return (checkend(buf, "end", "no \"end\" line"));
 +	case 0:
 +		return (0);
 +	case 1:
 +		return (1);
 +	default:
 +		return (checkend(buf, "end", "no \"end\" line"));
  	}
  }
  
 @@ -409,7 +414,7 @@ static int
  base64_decode(void)
  {
  	int n;
 -	char inbuf[MAXPATHLEN+1];
 +	char inbuf[MAXPATHLEN + 1];
  	unsigned char outbuf[MAXPATHLEN * 4];
  
  	for (;;) {
 @@ -418,21 +423,22 @@ base64_decode(void)
  		case 1: return (1);
  		}
  		n = b64_pton(inbuf, outbuf, sizeof(outbuf));
 +
  		if (n < 0)
  			break;
  		fwrite(outbuf, 1, n, outfp);
  	}
 -	return (checkend(inbuf, "====",
 -		    "error decoding base64 input stream"));
 +	return (checkend(inbuf, "====", "error decoding base64 input stream"));
  }
  
  static void
  usage(void)
  {
 +
  	(void)fprintf(stderr,
 -"usage: uudecode [-cimprs] [file ...]\n"
 -"       uudecode [-i] -o output_file [file]\n"
 -"       b64decode [-cimprs] [file ...]\n"
 -"       b64decode [-i] -o output_file [file]\n");
 +	    "usage: uudecode [-cimprs] [file ...]\n"
 +	    "       uudecode [-i] -o output_file [file]\n"
 +	    "       b64decode [-cimprs] [file ...]\n"
 +	    "       b64decode [-i] -o output_file [file]\n");
  	exit(1);
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: edwin 
State-Changed-When: Mon Oct 18 05:44:21 UTC 2010 
State-Changed-Why:  
Commited to HEAD 

http://www.freebsd.org/cgi/query-pr.cgi?pr=124739 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/124739: commit references a PR
Date: Mon, 18 Oct 2010 05:44:17 +0000 (UTC)

 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)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: edwin 
State-Changed-When: Wed Nov 3 10:12:20 UTC 2010 
State-Changed-Why:  
MFC into stable/8, stable/7 done. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=124739 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/124739: commit references a PR
Date: Wed,  3 Nov 2010 10:10:44 +0000 (UTC)

 Author: edwin
 Date: Wed Nov  3 10:10:34 2010
 New Revision: 214729
 URL: http://svn.freebsd.org/changeset/base/214729
 
 Log:
   MFC of r214002, r214010
   
   - Stylify of uudecode(1)
     Part of PR bin/124739.
   
   - "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>
 
 Modified:
   stable/8/usr.bin/uudecode/uudecode.c
 Directory Properties:
   stable/8/usr.bin/uudecode/   (props changed)
 
 Modified: stable/8/usr.bin/uudecode/uudecode.c
 ==============================================================================
 --- stable/8/usr.bin/uudecode/uudecode.c	Wed Nov  3 09:23:08 2010	(r214728)
 +++ stable/8/usr.bin/uudecode/uudecode.c	Wed Nov  3 10:10:34 2010	(r214729)
 @@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
  
  #include <netinet/in.h>
  
 +#include <ctype.h>
  #include <err.h>
  #include <errno.h>
  #include <fcntl.h>
 @@ -87,7 +88,7 @@ main(int argc, char *argv[])
  		base64 = 1;
  
  	while ((ch = getopt(argc, argv, "cimo:prs")) != -1) {
 -		switch(ch) {
 +		switch (ch) {
  		case 'c':
  			if (oflag || rflag)
  				usage();
 @@ -125,10 +126,10 @@ main(int argc, char *argv[])
  			usage();
  		}
  	}
 -        argc -= optind;
 -        argv += optind;
 +	argc -= optind;
 +	argv += optind;
  
 -	if (*argv) {
 +	if (*argv != NULL) {
  		rval = 0;
  		do {
  			infp = fopen(infile = *argv, "r");
 @@ -184,7 +185,7 @@ decode2(void)
  	void *handle;
  	struct passwd *pw;
  	struct stat st;
 -	char buf[MAXPATHLEN+1];
 +	char buf[MAXPATHLEN + 1];
  
  	base64 = 0;
  	/* search for header line */
 @@ -259,7 +260,7 @@ decode2(void)
  	if (pflag || strcmp(outfile, "/dev/stdout") == 0)
  		outfp = stdout;
  	else {
 -		flags = O_WRONLY|O_CREAT|O_EXCL;
 +		flags = O_WRONLY | O_CREAT | O_EXCL;
  		if (lstat(outfile, &st) == 0) {
  			if (iflag) {
  				warnc(EEXIST, "%s: %s", infile, outfile);
 @@ -305,6 +306,7 @@ decode2(void)
  static int
  getline(char *buf, size_t size)
  {
 +
  	if (fgets(buf, size, infp) != NULL)
  		return (2);
  	if (rflag)
 @@ -341,17 +343,19 @@ uu_decode(void)
  	/* for each input line */
  	for (;;) {
  		switch (getline(buf, sizeof(buf))) {
 -		case 0: return (0);
 -		case 1: return (1);
 +		case 0:
 +			return (0);
 +		case 1:
 +			return (1);
  		}
  
 -#define	DEC(c)	(((c) - ' ') & 077)		/* single character decode */
 -#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
 +#define	DEC(c)		(((c) - ' ') & 077)	/* single character decode */
 +#define IS_DEC(c)	 ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
  
  #define OUT_OF_RANGE do {						\
  	warnx("%s: %s: character out of range: [%d-%d]",		\
  	    infile, outfile, 1 + ' ', 077 + ' ' + 1);			\
 -        return (1);							\
 +	return (1);							\
  } while (0)
  
  		/*
 @@ -364,8 +368,8 @@ uu_decode(void)
  		for (++p; i > 0; p += 4, i -= 3)
  			if (i >= 3) {
  				if (!(IS_DEC(*p) && IS_DEC(*(p + 1)) &&
 -				     IS_DEC(*(p + 2)) && IS_DEC(*(p + 3))))
 -                                	OUT_OF_RANGE;
 +				    IS_DEC(*(p + 2)) && IS_DEC(*(p + 3))))
 +					OUT_OF_RANGE;
  
  				ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
  				putc(ch, outfp);
 @@ -373,8 +377,7 @@ uu_decode(void)
  				putc(ch, outfp);
  				ch = DEC(p[2]) << 6 | DEC(p[3]);
  				putc(ch, outfp);
 -			}
 -			else {
 +			} else {
  				if (i >= 1) {
  					if (!(IS_DEC(*p) && IS_DEC(*(p + 1))))
  	                                	OUT_OF_RANGE;
 @@ -383,56 +386,85 @@ uu_decode(void)
  				}
  				if (i >= 2) {
  					if (!(IS_DEC(*(p + 1)) &&
 -						IS_DEC(*(p + 2))))
 -		                                OUT_OF_RANGE;
 +					    IS_DEC(*(p + 2))))
 +						OUT_OF_RANGE;
  
  					ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
  					putc(ch, outfp);
  				}
  				if (i >= 3) {
  					if (!(IS_DEC(*(p + 2)) &&
 -						IS_DEC(*(p + 3))))
 -		                                OUT_OF_RANGE;
 +					    IS_DEC(*(p + 3))))
 +						OUT_OF_RANGE;
  					ch = DEC(p[2]) << 6 | DEC(p[3]);
  					putc(ch, outfp);
  				}
  			}
  	}
  	switch (getline(buf, sizeof(buf))) {
 -	case 0:  return (0);
 -	case 1:  return (1);
 -	default: return (checkend(buf, "end", "no \"end\" line"));
 +	case 0:
 +		return (0);
 +	case 1:
 +		return (1);
 +	default:
 +		return (checkend(buf, "end", "no \"end\" line"));
  	}
  }
  
  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)
  			break;
  		fwrite(outbuf, 1, n, outfp);
  	}
 -	return (checkend(inbuf, "====",
 -		    "error decoding base64 input stream"));
 +	return (checkend(inbuf, "====", "error decoding base64 input stream"));
  }
  
  static void
  usage(void)
  {
 +
  	(void)fprintf(stderr,
 -"usage: uudecode [-cimprs] [file ...]\n"
 -"       uudecode [-i] -o output_file [file]\n"
 -"       b64decode [-cimprs] [file ...]\n"
 -"       b64decode [-i] -o output_file [file]\n");
 +	    "usage: uudecode [-cimprs] [file ...]\n"
 +	    "       uudecode [-i] -o output_file [file]\n"
 +	    "       b64decode [-cimprs] [file ...]\n"
 +	    "       b64decode [-i] -o output_file [file]\n");
  	exit(1);
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/124739: commit references a PR
Date: Wed,  3 Nov 2010 10:12:20 +0000 (UTC)

 Author: edwin
 Date: Wed Nov  3 10:12:13 2010
 New Revision: 214730
 URL: http://svn.freebsd.org/changeset/base/214730
 
 Log:
   MFC of r214002, r214010
   
   - Stylify of uudecode(1)
     Part of PR bin/124739.
   
   - "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>
 
 Modified:
   stable/7/usr.bin/uudecode/uudecode.c
 Directory Properties:
   stable/7/usr.bin/uudecode/   (props changed)
 
 Modified: stable/7/usr.bin/uudecode/uudecode.c
 ==============================================================================
 --- stable/7/usr.bin/uudecode/uudecode.c	Wed Nov  3 10:10:34 2010	(r214729)
 +++ stable/7/usr.bin/uudecode/uudecode.c	Wed Nov  3 10:12:13 2010	(r214730)
 @@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
  
  #include <netinet/in.h>
  
 +#include <ctype.h>
  #include <err.h>
  #include <errno.h>
  #include <fcntl.h>
 @@ -87,7 +88,7 @@ main(int argc, char *argv[])
  		base64 = 1;
  
  	while ((ch = getopt(argc, argv, "cimo:prs")) != -1) {
 -		switch(ch) {
 +		switch (ch) {
  		case 'c':
  			if (oflag || rflag)
  				usage();
 @@ -125,10 +126,10 @@ main(int argc, char *argv[])
  			usage();
  		}
  	}
 -        argc -= optind;
 -        argv += optind;
 +	argc -= optind;
 +	argv += optind;
  
 -	if (*argv) {
 +	if (*argv != NULL) {
  		rval = 0;
  		do {
  			infp = fopen(infile = *argv, "r");
 @@ -184,7 +185,7 @@ decode2(void)
  	void *handle;
  	struct passwd *pw;
  	struct stat st;
 -	char buf[MAXPATHLEN+1];
 +	char buf[MAXPATHLEN + 1];
  
  	base64 = 0;
  	/* search for header line */
 @@ -259,7 +260,7 @@ decode2(void)
  	if (pflag || strcmp(outfile, "/dev/stdout") == 0)
  		outfp = stdout;
  	else {
 -		flags = O_WRONLY|O_CREAT|O_EXCL;
 +		flags = O_WRONLY | O_CREAT | O_EXCL;
  		if (lstat(outfile, &st) == 0) {
  			if (iflag) {
  				warnc(EEXIST, "%s: %s", infile, outfile);
 @@ -305,6 +306,7 @@ decode2(void)
  static int
  getline(char *buf, size_t size)
  {
 +
  	if (fgets(buf, size, infp) != NULL)
  		return (2);
  	if (rflag)
 @@ -341,17 +343,19 @@ uu_decode(void)
  	/* for each input line */
  	for (;;) {
  		switch (getline(buf, sizeof(buf))) {
 -		case 0: return (0);
 -		case 1: return (1);
 +		case 0:
 +			return (0);
 +		case 1:
 +			return (1);
  		}
  
 -#define	DEC(c)	(((c) - ' ') & 077)		/* single character decode */
 -#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
 +#define	DEC(c)		(((c) - ' ') & 077)	/* single character decode */
 +#define IS_DEC(c)	 ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
  
  #define OUT_OF_RANGE do {						\
  	warnx("%s: %s: character out of range: [%d-%d]",		\
  	    infile, outfile, 1 + ' ', 077 + ' ' + 1);			\
 -        return (1);							\
 +	return (1);							\
  } while (0)
  
  		/*
 @@ -364,8 +368,8 @@ uu_decode(void)
  		for (++p; i > 0; p += 4, i -= 3)
  			if (i >= 3) {
  				if (!(IS_DEC(*p) && IS_DEC(*(p + 1)) &&
 -				     IS_DEC(*(p + 2)) && IS_DEC(*(p + 3))))
 -                                	OUT_OF_RANGE;
 +				    IS_DEC(*(p + 2)) && IS_DEC(*(p + 3))))
 +					OUT_OF_RANGE;
  
  				ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
  				putc(ch, outfp);
 @@ -373,8 +377,7 @@ uu_decode(void)
  				putc(ch, outfp);
  				ch = DEC(p[2]) << 6 | DEC(p[3]);
  				putc(ch, outfp);
 -			}
 -			else {
 +			} else {
  				if (i >= 1) {
  					if (!(IS_DEC(*p) && IS_DEC(*(p + 1))))
  	                                	OUT_OF_RANGE;
 @@ -383,56 +386,85 @@ uu_decode(void)
  				}
  				if (i >= 2) {
  					if (!(IS_DEC(*(p + 1)) &&
 -						IS_DEC(*(p + 2))))
 -		                                OUT_OF_RANGE;
 +					    IS_DEC(*(p + 2))))
 +						OUT_OF_RANGE;
  
  					ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
  					putc(ch, outfp);
  				}
  				if (i >= 3) {
  					if (!(IS_DEC(*(p + 2)) &&
 -						IS_DEC(*(p + 3))))
 -		                                OUT_OF_RANGE;
 +					    IS_DEC(*(p + 3))))
 +						OUT_OF_RANGE;
  					ch = DEC(p[2]) << 6 | DEC(p[3]);
  					putc(ch, outfp);
  				}
  			}
  	}
  	switch (getline(buf, sizeof(buf))) {
 -	case 0:  return (0);
 -	case 1:  return (1);
 -	default: return (checkend(buf, "end", "no \"end\" line"));
 +	case 0:
 +		return (0);
 +	case 1:
 +		return (1);
 +	default:
 +		return (checkend(buf, "end", "no \"end\" line"));
  	}
  }
  
  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)
  			break;
  		fwrite(outbuf, 1, n, outfp);
  	}
 -	return (checkend(inbuf, "====",
 -		    "error decoding base64 input stream"));
 +	return (checkend(inbuf, "====", "error decoding base64 input stream"));
  }
  
  static void
  usage(void)
  {
 +
  	(void)fprintf(stderr,
 -"usage: uudecode [-cimprs] [file ...]\n"
 -"       uudecode [-i] -o output_file [file]\n"
 -"       b64decode [-cimprs] [file ...]\n"
 -"       b64decode [-i] -o output_file [file]\n");
 +	    "usage: uudecode [-cimprs] [file ...]\n"
 +	    "       uudecode [-i] -o output_file [file]\n"
 +	    "       b64decode [-cimprs] [file ...]\n"
 +	    "       b64decode [-i] -o output_file [file]\n");
  	exit(1);
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
