[hackers] [sbase] Audit uudecode(1) || FRIGN

From: <git_AT_suckless.org>
Date: Thu, 19 Mar 2015 11:13:24 +0100 (CET)

commit c11a5d0c68e4110a90f8e8b9af5a2dbb84c17587
Author: FRIGN <dev_AT_frign.de>
Date: Wed Mar 18 00:10:36 2015 +0100

    Audit uudecode(1)
    
    Style cleanup, Manpage refactoring.

diff --git a/README b/README
index 755d428..9727f85 100644
--- a/README
+++ b/README
_AT_@ -84,7 +84,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
 #*| unexpand yes none
 =*| uniq yes none
 =*| unlink yes none
-=* uudecode yes none
+=*| uudecode yes none
 =* uuencode yes none
 #* wc yes none
 = xargs no -I, -L, -p, -s, -t, -x
diff --git a/uudecode.1 b/uudecode.1
index 08cd7bd..c98ef17 100644
--- a/uudecode.1
+++ b/uudecode.1
_AT_@ -1,4 +1,4 @@
-.Dd February 13, 2015
+.Dd March 18, 2015
 .Dt UUDECODE 1
 .Os sbase
 .Sh NAME
_AT_@ -13,23 +13,27 @@
 .Nm
 reads
 .Ar file
-(or by default, the standard input) and writes a decoded
-version to the file specified in the uuencoded header. In case that
-the file already exists, it is truncated. Otherwise a new file is
-created. After the operation the permissions of the created/accessed
-are changed to reflect the mode in the header.
+and writes a decoded version to the file specified in the uuencoded header.
+In case the file already exists, it is truncated. Otherwise a new file is
+created. The permissions of the created/accessed file are changed to
+reflect the mode in the header.
+If no
+.Ar file
+is given
+.Nm
+reads from stdin.
 .Sh OPTIONS
 .Bl -tag -width Ds
 .It Fl m
 Use Base64 for decoding.
 .It Fl o Ar output
-Use the file specified by
+Write to
 .Ar output
-instead of standard output.
+rather than the file specified in the header.
 .El
 .Sh IMPLEMENTATION NOTES
-For safety currently uudecode operates only on regular files and
-stdout. Trying to uudecode to a link, directory, or special file
+For safety uudecode operates on regular files and stdout only.
+Trying to uudecode to a link, directory, or special file
 yields an error.
 .Sh SEE ALSO
 .Xr uuencode 1
diff --git a/uudecode.c b/uudecode.c
index 5412225..c722ab9 100644
--- a/uudecode.c
+++ b/uudecode.c
_AT_@ -17,7 +17,7 @@ parsefile(const char *fname)
         struct stat st;
         int ret;
 
- if (strcmp(fname, "/dev/stdout") == 0 || strcmp(fname, "-") == 0)
+ if (!strcmp(fname, "/dev/stdout") || !strcmp(fname, "-"))
                 return stdout;
         ret = lstat(fname, &st);
         /* if it is a new file, try to open it */
_AT_@ -32,12 +32,11 @@ parsefile(const char *fname)
                 return NULL;
         }
 tropen:
- return fopen(fname,"w");
+ return fopen(fname, "w");
 }
 
 static void
-parseheader(FILE *fp, const char *s, char **header, mode_t *mode,
- char **fname)
+parseheader(FILE *fp, const char *s, char **header, mode_t *mode, char **fname)
 {
         char bufs[PATH_MAX + 18]; /* len header + mode + maxname */
         char *p, *q;
_AT_@ -74,8 +73,8 @@ parseheader(FILE *fp, const char *s, char **header, mode_t *mode,
 static const char b64dt[] = {
         -1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
         -1,-1,-1,-1,-1,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
- 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,0,-1,-1,-1,0,1,2,3,4,5,6,
- 7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
+ 52,53,54,55,56,57,58,59,60,61,-1,-1,-1, 0,-1,-1,-1, 0, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
         -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
         49,50,51,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
         -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
_AT_@ -212,7 +211,7 @@ uudecode(FILE *fp, FILE *outfp)
         }
         /* check for end or fail */
         len = getline(&bufb, &n, fp);
- if (len < 3 || strncmp(bufb, "end", 3) != 0 || bufb[3] != '\n')
+ if (len < 3 || strncmp(bufb, "end", 3) || bufb[3] != '\n')
                 eprintf("invalid uudecode footer \"end\" not found\n");
         free(bufb);
 }
_AT_@ -227,11 +226,9 @@ int
 main(int argc, char *argv[])
 {
         FILE *fp = NULL, *nfp = NULL;
- char *fname, *header;
- const char *ifname;
         mode_t mode = 0;
+ char *fname, *header, *ifname, *ofname = NULL;
         void (*d) (FILE *, FILE *) = NULL;
- char *ofname = NULL;
 
         ARGBEGIN {
         case 'm':
_AT_@ -248,7 +245,7 @@ main(int argc, char *argv[])
         if (argc > 1)
                 usage();
 
- if (argc == 0) {
+ if (!argc) {
                 fp = stdin;
                 ifname = "<stdin>";
         } else {
Received on Thu Mar 19 2015 - 11:13:24 CET

This archive was generated by hypermail 2.3.0 : Thu Mar 19 2015 - 11:24:37 CET