summaryrefslogtreecommitdiff
path: root/usr.bin/uuencode/uuencode.c
diff options
context:
space:
mode:
authorrin <rin@NetBSD.org>2019-03-04 05:37:08 +0000
committerrin <rin@NetBSD.org>2019-03-04 05:37:08 +0000
commita6442db8d98fceb7dbb08784436ce7a7eb301530 (patch)
tree20ca726a8772549e6daa93ed192836e75bc718cc /usr.bin/uuencode/uuencode.c
parent4b7b251d1375089fc32a0c199d5ff8b35a5b8881 (diff)
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.
Diffstat (limited to 'usr.bin/uuencode/uuencode.c')
-rw-r--r--usr.bin/uuencode/uuencode.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.bin/uuencode/uuencode.c b/usr.bin/uuencode/uuencode.c
index 50b70513415..8ac8313c895 100644
--- a/usr.bin/uuencode/uuencode.c
+++ b/usr.bin/uuencode/uuencode.c
@@ -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, 1993\
#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)