[hackers] [sbase] Handle { NULL } argv[] properly in manual arg-reduction || Laslo Hunhold
commit e92a1aef54570e86d778da84847e6d8d9e924487
Author: Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Sat Aug 5 23:50:39 2017 +0200
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Sat Aug 5 23:50:39 2017 +0200
Handle { NULL } argv[] properly in manual arg-reduction
Thanks izabera for reporting this!
diff --git a/basename.c b/basename.c
index 4a6ac2a..d211799 100644
--- a/basename.c
+++ b/basename.c
_AT_@ -17,7 +17,7 @@ main(int argc, char *argv[])
ssize_t off;
char *p;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1 && argc != 2)
usage();
diff --git a/chmod.c b/chmod.c
index 109a7e5..f671f32 100644
--- a/chmod.c
+++ b/chmod.c
_AT_@ -35,7 +35,7 @@ main(int argc, char *argv[])
.follow = 'P', .flags = 0 };
size_t i;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
for (; *argv && (*argv)[0] == '-'; argc--, argv++) {
if (!(*argv)[1])
diff --git a/chroot.c b/chroot.c
index 0b797cc..22bc62e 100644
--- a/chroot.c
+++ b/chroot.c
_AT_@ -17,7 +17,7 @@ main(int argc, char *argv[])
char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *cmd;
int savederrno;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc)
usage();
diff --git a/cksum.c b/cksum.c
index b53ec17..4e7dce6 100644
--- a/cksum.c
+++ b/cksum.c
_AT_@ -97,7 +97,7 @@ main(int argc, char *argv[])
{
int fd;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) {
cksum(0, NULL);
diff --git a/dirname.c b/dirname.c
index 4bef9a4..8392bc0 100644
--- a/dirname.c
+++ b/dirname.c
_AT_@ -13,7 +13,7 @@ usage(void)
int
main(int argc, char *argv[])
{
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1)
usage();
diff --git a/echo.c b/echo.c
index 23bc55f..a552631 100644
--- a/echo.c
+++ b/echo.c
_AT_@ -8,7 +8,7 @@ main(int argc, char *argv[])
{
int nflag = 0;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (*argv && !strcmp(*argv, "-n")) {
nflag = 1;
diff --git a/expr.c b/expr.c
index 4570b33..d9c758d 100644
--- a/expr.c
+++ b/expr.c
_AT_@ -257,7 +257,7 @@ main(int argc, char *argv[])
{
int ret;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
ret = !parse(argv, argc);
diff --git a/hostname.c b/hostname.c
index a0e3969..495d40d 100644
--- a/hostname.c
+++ b/hostname.c
_AT_@ -16,7 +16,7 @@ main(int argc, char *argv[])
{
char host[HOST_NAME_MAX + 1];
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) {
if (gethostname(host, sizeof(host)) < 0)
diff --git a/kill.c b/kill.c
index f7dd132..e3751a0 100644
--- a/kill.c
+++ b/kill.c
_AT_@ -62,7 +62,8 @@ main(int argc, char *argv[])
size_t i;
int ret = 0, sig = SIGTERM;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
+
if (!argc)
usage();
diff --git a/link.c b/link.c
index e169f0a..a260136 100644
--- a/link.c
+++ b/link.c
_AT_@ -12,7 +12,7 @@ usage(void)
int
main(int argc, char *argv[])
{
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 2)
usage();
diff --git a/logname.c b/logname.c
index 2a591cd..8eb8eea 100644
--- a/logname.c
+++ b/logname.c
_AT_@ -15,7 +15,7 @@ main(int argc, char *argv[])
{
char *login;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc)
usage();
diff --git a/nohup.c b/nohup.c
index 080b210..c75ea45 100644
--- a/nohup.c
+++ b/nohup.c
_AT_@ -19,7 +19,7 @@ main(int argc, char *argv[])
{
int fd, savederrno;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc)
usage();
diff --git a/printenv.c b/printenv.c
index 2e1d15b..7ff5393 100644
--- a/printenv.c
+++ b/printenv.c
_AT_@ -12,7 +12,7 @@ main(int argc, char *argv[])
char *var;
int ret = 0;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) {
for (; *environ; environ++)
diff --git a/setsid.c b/setsid.c
index 4c885a4..eb682f2 100644
--- a/setsid.c
+++ b/setsid.c
_AT_@ -15,7 +15,7 @@ main(int argc, char *argv[])
{
int savederrno;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc)
usage();
diff --git a/sleep.c b/sleep.c
index b1028ed..36dfb1c 100644
--- a/sleep.c
+++ b/sleep.c
_AT_@ -14,7 +14,7 @@ main(int argc, char *argv[])
{
unsigned seconds;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1)
usage();
diff --git a/sponge.c b/sponge.c
index da8b28c..11c8ad4 100644
--- a/sponge.c
+++ b/sponge.c
_AT_@ -17,7 +17,7 @@ main(int argc, char *argv[])
char tmp[] = "/tmp/sponge-XXXXXX";
int fd, tmpfd;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1)
usage();
diff --git a/sync.c b/sync.c
index 15e53f4..d3390de 100644
--- a/sync.c
+++ b/sync.c
_AT_@ -12,7 +12,7 @@ usage(void)
int
main(int argc, char *argv[])
{
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc)
usage();
diff --git a/test.c b/test.c
index 5cb0e20..1e88a22 100644
--- a/test.c
+++ b/test.c
_AT_@ -234,9 +234,9 @@ main(int argc, char *argv[])
int (*narg[])(char *[]) = { noarg, onearg, twoarg, threearg, fourarg };
size_t len;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
- len = strlen(argv0);
+ len = argv0 ? strlen(argv0) : 0;
if (len && argv0[--len] == '[' && (!len || argv0[--len] == '/') && strcmp(argv[--argc], "]"))
enprintf(2, "no matching ]\n");
diff --git a/tty.c b/tty.c
index 5afec79..a57cb8e 100644
--- a/tty.c
+++ b/tty.c
_AT_@ -15,7 +15,7 @@ main(int argc, char *argv[])
{
char *tty;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc)
usage();
diff --git a/unlink.c b/unlink.c
index bdc6061..241cf25 100644
--- a/unlink.c
+++ b/unlink.c
_AT_@ -12,7 +12,7 @@ usage(void)
int
main(int argc, char *argv[])
{
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc != 1)
usage();
diff --git a/whoami.c b/whoami.c
index 11ee7e2..c991ac2 100644
--- a/whoami.c
+++ b/whoami.c
_AT_@ -18,7 +18,7 @@ main(int argc, char *argv[])
uid_t uid;
struct passwd *pw;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (argc)
usage();
diff --git a/yes.c b/yes.c
index cbd81dc..dd97ea6 100644
--- a/yes.c
+++ b/yes.c
_AT_@ -8,7 +8,7 @@ main(int argc, char *argv[])
{
char **p;
- argv0 = argv[0], argc--, argv++;
+ argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) {
fputs(*p ? *p : "y", stdout);
Received on Sat Aug 05 2017 - 23:51:24 CEST
This archive was generated by hypermail 2.3.0
: Sun Aug 06 2017 - 00:00:49 CEST