Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/uuencode When input is not a multiple of three bytes...



details:   https://anonhg.NetBSD.org/src/rev/8320b444f141
branches:  trunk
changeset: 997317:8320b444f141
user:      rin <rin%NetBSD.org@localhost>
date:      Mon Mar 04 05:37:08 2019 +0000

description:
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:

 usr.bin/uuencode/uuencode.5 |  10 +++++-----
 usr.bin/uuencode/uuencode.c |  10 ++++++++--
 2 files changed, 13 insertions(+), 7 deletions(-)

diffs (64 lines):

diff -r e9e6488cce04 -r 8320b444f141 usr.bin/uuencode/uuencode.5
--- a/usr.bin/uuencode/uuencode.5       Mon Mar 04 05:28:48 2019 +0000
+++ b/usr.bin/uuencode/uuencode.5       Mon Mar 04 05:37:08 2019 +0000
@@ -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 @@
 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
diff -r e9e6488cce04 -r 8320b444f141 usr.bin/uuencode/uuencode.c
--- a/usr.bin/uuencode/uuencode.c       Mon Mar 04 05:28:48 2019 +0000
+++ b/usr.bin/uuencode/uuencode.c       Mon Mar 04 05:37:08 2019 +0000
@@ -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 @@
 #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 @@
                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)



Home | Main Index | Thread Index | Old Index