[hackers] [sbase] Audit printenv(1) || FRIGN
commit 0226c051056e873d7faa46434b1b012eac59af12
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 Tue Mar 24 2015 - 23:54:02 CET
This archive was generated by hypermail 2.3.0
: Wed Mar 25 2015 - 00:10:51 CET