audit small applets and mark some of them as NOFORK.

Put big scary warnings in relevant places.
This commit is contained in:
Denis Vlasenko
2007-04-10 15:43:37 +00:00
parent ff131b980d
commit 99912ca733
41 changed files with 173 additions and 128 deletions
+3 -4
View File
@@ -20,11 +20,10 @@
* 3) Save some space by using strcmp(). Calling strncmp() here was silly.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int basename_main(int argc, char **argv);
int basename_main(int argc, char **argv)
{
@@ -47,5 +46,5 @@ int basename_main(int argc, char **argv)
puts(s);
fflush_stdout_and_exit(EXIT_SUCCESS);
return fflush(stdout);
}
+7 -1
View File
@@ -12,17 +12,23 @@
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int bb_cat(char **argv)
{
static const char *const argv_dash[] = { "-", NULL };
FILE *f;
int retval = EXIT_SUCCESS;
if (!*argv) argv = (char**) &argv_dash;
if (!*argv)
argv = (char**) &argv_dash;
do {
f = fopen_or_warn_stdin(*argv);
if (f) {
/* This is not an xfunc - never exits */
off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
fclose_if_not_stdin(f);
if (r >= 0)
+3
View File
@@ -13,6 +13,9 @@
#include "busybox.h"
/* This is a NOEXEC applet. Be very careful! */
int chgrp_main(int argc, char **argv);
int chgrp_main(int argc, char **argv)
{
+3
View File
@@ -16,6 +16,9 @@
#include "busybox.h"
/* This is a NOEXEC applet. Be very careful! */
#define OPT_RECURSE (option_mask32 & 1)
#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 2) SKIP_DESKTOP(0))
#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 4) SKIP_DESKTOP(0))
+3
View File
@@ -13,6 +13,9 @@
#include "busybox.h"
/* This is a NOEXEC applet. Be very careful! */
#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
#define BIT_RECURSE 1
#define OPT_RECURSE (option_mask32 & 1)
+3 -2
View File
@@ -27,8 +27,9 @@ int chroot_main(int argc, char **argv)
++argv;
if (argc == 2) {
argv -= 2;
if (!(*argv = getenv("SHELL"))) {
*argv = (char *) DEFAULT_SHELL;
argv[0] = getenv("SHELL");
if (!argv[0]) {
argv[0] = (char *) DEFAULT_SHELL;
}
argv[1] = (char *) "-i";
}
+3
View File
@@ -18,6 +18,9 @@
#include "busybox.h"
#include "libcoreutils/coreutils.h"
/* This is a NOEXEC applet. Be very careful! */
int cp_main(int argc, char **argv);
int cp_main(int argc, char **argv)
{
+3
View File
@@ -11,6 +11,9 @@
#include "busybox.h"
/* This is a NOEXEC applet. Be very careful! */
/* option vars */
static const char optstring[] = "b:c:f:d:sn";
#define CUT_OPT_BYTE_FLGS (1<<0)
+4 -1
View File
@@ -8,8 +8,11 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "busybox.h"
#include <signal.h> /* For FEATURE_DD_SIGNAL_HANDLING */
#include "busybox.h"
/* This is a NOEXEC applet. Be very careful! */
static const struct suffix_mult dd_suffixes[] = {
{ "c", 1 },
+3 -3
View File
@@ -10,10 +10,10 @@
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/dirname.html */
#include <stdio.h>
#include <stdlib.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int dirname_main(int argc, char **argv);
int dirname_main(int argc, char **argv)
{
@@ -23,5 +23,5 @@ int dirname_main(int argc, char **argv)
puts(dirname(argv[1]));
fflush_stdout_and_exit(EXIT_SUCCESS);
return fflush(stdout);
}
+2 -1
View File
@@ -10,9 +10,10 @@
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/false.html */
#include <stdlib.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv);
int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv)
{
+3 -3
View File
@@ -9,10 +9,10 @@
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
#include <stdlib.h>
#include <unistd.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv);
int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv)
{
@@ -22,5 +22,5 @@ int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv)
printf("%lx\n", gethostid());
fflush_stdout_and_exit(EXIT_SUCCESS);
return fflush(stdout);
}
+6 -7
View File
@@ -2,19 +2,18 @@
/* BB_AUDIT SUSv3 N/A -- Apparently a busybox (obsolete?) extension. */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int length_main(int argc, char **argv);
int length_main(int argc, char **argv)
{
if ((argc != 2) || (**(++argv) == '-')) {
bb_show_usage();
if ((argc != 2) || (**(++argv) == '-')) {
bb_show_usage();
}
printf("%lu\n", (unsigned long)strlen(*argv));
printf("%u\n", (unsigned)strlen(*argv));
fflush_stdout_and_exit(EXIT_SUCCESS);
return fflush(stdout);
}
+3
View File
@@ -13,6 +13,9 @@
#include "busybox.h"
/* This is a NOEXEC applet. Be very careful! */
#define LN_SYMLINK 1
#define LN_FORCE 2
#define LN_NODEREFERENCE 4
+7 -7
View File
@@ -20,23 +20,23 @@
* a diagnostic message and an error return.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int logname_main(int argc, char ATTRIBUTE_UNUSED **argv);
int logname_main(int argc, char ATTRIBUTE_UNUSED **argv)
{
const char *p;
char buf[128];
if (argc > 1) {
bb_show_usage();
}
if ((p = getlogin()) != NULL) {
puts(p);
fflush_stdout_and_exit(EXIT_SUCCESS);
/* Using _r function - avoid pulling in static buffer from libc */
if (getlogin_r(buf, sizeof(buf)) == 0) {
puts(buf);
return fflush(stdout);
}
bb_perror_msg_and_die("getlogin");
+4 -1
View File
@@ -29,8 +29,11 @@
* 1. requires lstat (BSD) - how do you do it without?
*/
#include "busybox.h"
#include <getopt.h>
#include "busybox.h"
/* This is a NOEXEC applet. Be very careful! */
enum {
+4 -4
View File
@@ -19,19 +19,19 @@
/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
*/
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h> /* struct option */
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
static const struct option mkdir_long_options[] = {
{ "mode", 1, NULL, 'm' },
{ "mode" , 1, NULL, 'm' },
{ "parents", 0, NULL, 'p' },
#if ENABLE_SELINUX
{ "context", 1, NULL, 'Z' },
#endif
{ 0, 0, 0, 0 }
{ NULL, 0, NULL, 0 }
};
#endif
+2 -4
View File
@@ -10,9 +10,6 @@
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkfifo.html */
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include "busybox.h"
#include "libcoreutils/coreutils.h"
@@ -24,7 +21,8 @@ int mkfifo_main(int argc, char **argv)
mode = getopt_mk_fifo_nod(argc, argv);
if (!*(argv += optind)) {
argv += optind;
if (!*argv) {
bb_show_usage();
}
+4 -3
View File
@@ -7,10 +7,10 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <stdio.h>
#include <stdlib.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int pwd_main(int argc, char **argv);
int pwd_main(int argc, char **argv)
{
@@ -19,7 +19,8 @@ int pwd_main(int argc, char **argv)
buf = xrealloc_getcwd_or_warn(NULL);
if (buf != NULL) {
puts(buf);
fflush_stdout_and_exit(EXIT_SUCCESS);
free(buf);
return fflush(stdout);
}
return EXIT_FAILURE;
+5 -3
View File
@@ -15,9 +15,10 @@
* Size reduction.
*/
#include <unistd.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int rm_main(int argc, char **argv);
int rm_main(int argc, char **argv)
{
@@ -27,14 +28,15 @@ int rm_main(int argc, char **argv)
opt_complementary = "f-i:i-f";
opt = getopt32(argc, argv, "fiRr");
argv += optind;
if(opt & 1)
flags |= FILEUTILS_FORCE;
flags |= FILEUTILS_FORCE;
if(opt & 2)
flags |= FILEUTILS_INTERACTIVE;
if(opt & 12)
flags |= FILEUTILS_RECUR;
if (*(argv += optind) != NULL) {
if (*argv != NULL) {
do {
const char *base = bb_get_last_path_component(*argv);
+5 -5
View File
@@ -10,11 +10,12 @@
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/rmdir.html */
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int rmdir_main(int argc, char **argv);
int rmdir_main(int argc, char **argv)
{
@@ -24,7 +25,6 @@ int rmdir_main(int argc, char **argv)
char *path;
flags = getopt32(argc, argv, "p");
argv += optind;
if (!*argv) {
@@ -37,7 +37,7 @@ int rmdir_main(int argc, char **argv)
/* Record if the first char was a '.' so we can use dirname later. */
do_dot = (*path == '.');
do {
while (1) {
if (rmdir(path) < 0) {
bb_perror_msg("'%s'", path); /* Match gnu rmdir msg. */
status = EXIT_FAILURE;
@@ -53,7 +53,7 @@ int rmdir_main(int argc, char **argv)
}
}
break;
} while (1);
}
} while (*++argv);
+9 -10
View File
@@ -7,21 +7,22 @@
* Licensed under the GPL v2, see the file LICENSE in this tarball.
*/
#include <stdio.h>
#include <stdlib.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int seq_main(int argc, char **argv);
int seq_main(int argc, char **argv)
{
double last, first, increment, i;
double last, increment, i;
first = increment = 1;
i = increment = 1;
switch (argc) {
case 4:
increment = atof(argv[2]);
case 3:
first = atof(argv[1]);
i = atof(argv[1]);
case 2:
last = atof(argv[argc-1]);
break;
@@ -30,12 +31,10 @@ int seq_main(int argc, char **argv)
}
/* You should note that this is pos-5.0.91 semantics, -- FK. */
for (i = first;
(increment > 0 && i <= last) || (increment < 0 && i >=last);
i += increment)
{
while ((increment > 0 && i <= last) || (increment < 0 && i >= last)) {
printf("%g\n", i);
i += increment;
}
return EXIT_SUCCESS;
return fflush(stdout);
}
+8 -8
View File
@@ -18,12 +18,12 @@
* time suffixes for seconds, minutes, hours, and days.
*/
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
#include "busybox.h"
#ifdef CONFIG_FEATURE_FANCY_SLEEP
/* This is a NOFORK applet. Be very careful! */
#if ENABLE_FEATURE_FANCY_SLEEP
static const struct suffix_mult sfx[] = {
{ "s", 1 },
{ "m", 60 },
@@ -36,9 +36,9 @@ static const struct suffix_mult sfx[] = {
int sleep_main(int argc, char **argv);
int sleep_main(int argc, char **argv)
{
unsigned int duration;
unsigned duration;
#ifdef CONFIG_FEATURE_FANCY_SLEEP
#if ENABLE_FEATURE_FANCY_SLEEP
if (argc < 2) {
bb_show_usage();
@@ -50,7 +50,7 @@ int sleep_main(int argc, char **argv)
duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx);
} while (*++argv);
#else /* CONFIG_FEATURE_FANCY_SLEEP */
#else /* FEATURE_FANCY_SLEEP */
if (argc != 2) {
bb_show_usage();
@@ -58,7 +58,7 @@ int sleep_main(int argc, char **argv)
duration = xatou(argv[1]);
#endif /* CONFIG_FEATURE_FANCY_SLEEP */
#endif /* FEATURE_FANCY_SLEEP */
if (sleep(duration)) {
bb_perror_nomsg_and_die();
+3
View File
@@ -14,6 +14,9 @@
#include "busybox.h"
/* This is a NOEXEC applet. Be very careful! */
/*
sort [-m][-o output][-bdfinru][-t char][-k keydef]... [file...]
sort -c [-bdfinru][-t char][-k keydef][file]
+2 -2
View File
@@ -9,10 +9,10 @@
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
#include <stdlib.h>
#include <unistd.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int sync_main(int argc, char **argv);
int sync_main(int argc, char **argv)
{
+3 -4
View File
@@ -21,12 +21,11 @@
*/
#include "busybox.h"
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <setjmp.h>
/* This is a NOEXEC applet. Be very careful! */
/* test(1) accepts the following grammar:
oexpr ::= aexpr | aexpr "-o" oexpr ;
aexpr ::= nexpr | nexpr "-a" aexpr ;
+2 -1
View File
@@ -10,9 +10,10 @@
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/true.html */
#include <stdlib.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int true_main(int argc, char **argv);
int true_main(int argc, char **argv)
{
+2 -4
View File
@@ -10,9 +10,6 @@
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/tty.html */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "busybox.h"
int tty_main(int argc, char **argv);
@@ -31,7 +28,8 @@ int tty_main(int argc, char **argv)
retval = 0;
if ((s = ttyname(0)) == NULL) {
s = ttyname(0);
if (s == NULL) {
/* According to SUSv3, ttyname can on fail with EBADF or ENOTTY.
* We know the file descriptor is good, so failure means not a tty. */
s = "not a tty";
+2 -3
View File
@@ -9,11 +9,10 @@
/* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int usleep_main(int argc, char **argv);
int usleep_main(int argc, char **argv)
{
+4 -5
View File
@@ -9,11 +9,10 @@
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int whoami_main(int argc, char **argv);
int whoami_main(int argc, char **argv)
{
@@ -21,6 +20,6 @@ int whoami_main(int argc, char **argv)
bb_show_usage();
puts(bb_getpwuid(NULL, geteuid(), -1));
/* exits on error */
fflush_stdout_and_exit(EXIT_SUCCESS);
return fflush(stdout);
}
+9 -8
View File
@@ -16,25 +16,26 @@
#include "busybox.h"
/* This is a NOFORK applet. Be very careful! */
int yes_main(int argc, char **argv);
int yes_main(int argc, char **argv)
{
static const char fmt_str[] = " %s";
const char *fmt;
char **first_arg;
*argv = (char*)"y";
argv[0] = (char*)"y";
if (argc != 1) {
++argv;
}
first_arg = argv;
do {
fmt = fmt_str + 1;
do {
printf(fmt, *argv);
fmt = fmt_str;
} while (*++argv);
while (1) {
fputs(*argv, stdout);
if (!*++argv)
break;
putchar(' ');
}
argv = first_arg;
} while (putchar('\n') != EOF);