[hackers] [sbase] Audit chroot(1) || FRIGN
commit c47101a5798774626aab18d2dea1e946c602de99
Author: FRIGN <dev_AT_frign.de>
Date: Mon Mar 2 17:41:58 2015 +0100
Audit chroot(1)
1) Fix usage()
2) Rename *p to *cmd
3) _exit trick with 126 + (savederrno == ENOENT)
4) return-style-fix
diff --git a/README b/README
index a73d8b7..0375e1b 100644
--- a/README
+++ b/README
_AT_@ -15,7 +15,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
=* chgrp yes none
=* chmod yes none
=* chown yes none
-=* chroot non-posix none
+=*| chroot non-posix none
=* cksum yes none
=* cmp yes none
#* cols non-posix none
diff --git a/chroot.c b/chroot.c
index 8cf764d..5048c78 100644
--- a/chroot.c
+++ b/chroot.c
_AT_@ -8,13 +8,13 @@
static void
usage(void)
{
- eprintf("usage: chroot dir [cmd [arg ...]]\n");
+ eprintf("usage: %s dir [cmd [arg ...]]\n", argv0);
}
int
main(int argc, char *argv[])
{
- char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *p;
+ char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *cmd;
int savederrno;
ARGBEGIN {
_AT_@ -22,7 +22,7 @@ main(int argc, char *argv[])
usage();
} ARGEND;
- if (argc < 1)
+ if (!argc)
usage();
if ((aux = getenv("SHELL")))
_AT_@ -35,16 +35,16 @@ main(int argc, char *argv[])
eprintf("chdir:");
if (argc == 1) {
- p = *shell;
+ cmd = *shell;
execvp(*shell, shell);
} else {
- p = argv[1];
- execvp(argv[1], argv+1);
+ cmd = argv[1];
+ execvp(argv[1], argv + 1);
}
savederrno = errno;
- weprintf("execvp %s:", p);
- _exit(savederrno == ENOENT ? 127 : 126);
- /* unreachable */
- return 0;
+ weprintf("execvp %s:", cmd);
+ _exit(126 + (savederrno == ENOENT));
+
+ return 0; /* not reached */
}
Received on Tue Mar 03 2015 - 14:32:26 CET
This archive was generated by hypermail 2.3.0
: Tue Mar 03 2015 - 14:36:31 CET