Module Name:    src
Committed By:   rin
Date:           Mon Mar  4 05:37:08 UTC 2019

Modified Files:
        src/usr.bin/uuencode: uuencode.5 uuencode.c

Log Message:
When input is not a multiple of three bytes in size, pad null
characters instead of garbage. This makes output reproducible.

Taken from FreeBSD:
https://svnweb.freebsd.org/base?view=revision&revision=84715

Even though this is not demanded by POSIX, uuencode(1) in
FreeBSD, OpenBSD, macOS, and GNU, behaves that way.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/uuencode/uuencode.5
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/uuencode/uuencode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/uuencode/uuencode.5
diff -u src/usr.bin/uuencode/uuencode.5:1.12 src/usr.bin/uuencode/uuencode.5:1.13
--- src/usr.bin/uuencode/uuencode.5:1.12	Mon Jun  6 15:09:33 2016
+++ src/usr.bin/uuencode/uuencode.5	Mon Mar  4 05:37:08 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: uuencode.5,v 1.12 2016/06/06 15:09:33 abhinav Exp $
+.\"	$NetBSD: uuencode.5,v 1.13 2019/03/04 05:37:08 rin Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)uuencode.format.5	8.2 (Berkeley) 1/12/94
 .\"
-.Dd June 2, 2016
+.Dd March 4, 2019
 .Dt UUENCODE 5
 .Os
 .Sh NAME
@@ -118,11 +118,11 @@ backquote character \`).
 Obviously, not every input file will be a multiple of three bytes in size.
 In these cases,
 .Xr uuencode 1
-will pad the remaining one or two bytes of data with garbage bytes until
+will pad the remaining one or two bytes of data with null characters until
 a three byte group is created.
 The byte count in a line containing
-garbage padding will reflect the actual number of bytes encoded, making
-it possible to convey how many bytes are garbage.
+null padding will reflect the actual number of bytes encoded, making
+it possible to convey how many bytes are null.
 .Pp
 The trailer line consists of
 .Dq end

Index: src/usr.bin/uuencode/uuencode.c
diff -u src/usr.bin/uuencode/uuencode.c:1.16 src/usr.bin/uuencode/uuencode.c:1.17
--- src/usr.bin/uuencode/uuencode.c:1.16	Sat Sep  6 18:58:35 2014
+++ src/usr.bin/uuencode/uuencode.c	Mon Mar  4 05:37:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: uuencode.c,v 1.16 2014/09/06 18:58:35 dholland Exp $	*/
+/*	$NetBSD: uuencode.c,v 1.17 2019/03/04 05:37:08 rin Exp $	*/
 
 /*-
  * Copyright (c) 1983, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "@(#)uuencode.c	8.2 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: uuencode.c,v 1.16 2014/09/06 18:58:35 dholland Exp $");
+__RCSID("$NetBSD: uuencode.c,v 1.17 2019/03/04 05:37:08 rin Exp $");
 #endif
 #endif /* not lint */
 
@@ -165,6 +165,12 @@ encode(void)
 		if (putchar(ch) == EOF)
 			break;
 		for (p = buf; n > 0; n -= 3, p += 3) {
+			/* Pad with nulls if not a multiple of 3. */
+			if (n < 3) {
+				p[2] = '\0';
+				if (n < 2)
+					p[1] = '\0';
+			}
 			ch = *p >> 2;
 			ch = ENC(ch);
 			if (putchar(ch) == EOF)

Reply via email to