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

From: <git_AT_suckless.org>
Date: Sat, 28 Feb 2015 22:12:23 +0100 (CET)

commit 05198cfd27d927704b14f02dba17376c9e9c4268
Author: FRIGN <dev_AT_frign.de>
Date: Sat Feb 28 21:47:17 2015 +0100

    Audit printenv(1)
    
    1) argc style
    2) safeguard argv-loop as already seen in echo(1) with argc-decrement.

diff --git a/README b/README
index 4a2d7a2..7bccbf6 100644
--- a/README
+++ b/README
_AT_@ -51,7 +51,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
 = nl no -d, -f, -h, -l, -p
 =* nohup yes none
 #* paste yes none
-=* printenv non-posix none
+=*| printenv non-posix none
 #* printf yes none
 =* pwd yes none
 = readlink non-posix none
diff --git a/echo.c b/echo.c
index 2ae8af9..8b58bcc 100644
--- a/echo.c
+++ b/echo.c
_AT_@ -23,7 +23,7 @@ main(int argc, char *argv[])
         } ARGEND;
 
         for (; argc > 0; argc--, argv++)
- putword(argv[0]);
+ putword(*argv);
         if (!nflag)
                 putchar('\n');
 
diff --git a/printenv.c b/printenv.c
index 675a6f9..ff210cb 100644
--- a/printenv.c
+++ b/printenv.c
_AT_@ -9,7 +9,7 @@ extern char **environ;
 static void
 usage(void)
 {
- eprintf("usage: %s [variable...]\n", argv0);
+ eprintf("usage: %s [var ...]\n", argv0);
 }
 
 int
_AT_@ -23,16 +23,17 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
- if (argc == 0) {
+ if (!argc) {
                 while (*environ)
                         printf("%s\n", *environ++);
         } else {
- while (*argv) {
- if ((var = getenv(*argv++)))
+ for (; argc > 0; argc--, argv++) {
+ if ((var = getenv(*argv)))
                                 printf("%s\n", var);
                         else
                                 ret = 1;
                 }
         }
+
         return ret;
 }
Received on Sat Feb 28 2015 - 22:12:23 CET

This archive was generated by hypermail 2.3.0 : Sat Feb 28 2015 - 22:24:15 CET