tar: sanitize option handling

This commit is contained in:
Denis Vlasenko
2006-11-24 21:54:44 +00:00
parent b833ca9d2d
commit d031ffa623
8 changed files with 175 additions and 215 deletions

View File

@@ -147,6 +147,40 @@ const char *opt_complementary
Special characters:
"-" A dash as the first char in a opt_complementary group forces
all arguments to be treated as options, even if they have
no leading dashes. Next char in this case can't be a digit (0-9),
use ':' or end of line. For example:
opt_complementary = "-:w-x:x-w";
getopt32(argc, argv, "wx");
Allows any arguments to be given without a dash (./program w x)
as well as with a dash (./program -x).
"--" A double dash at the beginning of opt_complementary means the
argv[1] string should always be treated as options, even if it isn't
prefixed with a "-". This is useful for special syntax in applets
such as "ar" and "tar":
tar xvf foo.tar
"-N" A dash as the first char in a opt_complementary group followed
by a single digit (0-9) means that at least N non-option
arguments must be present on the command line
"=N" An equal sign as the first char in a opt_complementary group followed
by a single digit (0-9) means that exactly N non-option
arguments must be present on the command line
"?N" A "?" as the first char in a opt_complementary group followed
by a single digit (0-9) means that at most N arguments must be present
on the command line.
"V-" An option with dash before colon or end-of-line results in
bb_show_usage being called if this option is encountered.
This is typically used to implement "print verbose usage message
and exit" option.
"-" A dash between two options causes the second of the two
to be unset (and ignored) if it is given on the command line.
@@ -173,30 +207,6 @@ Special characters:
if (opt & 4)
printf("Detected odd -x usage\n");
"-" A dash as the first char in a opt_complementary group forces
all arguments to be treated as options, even if they have
no leading dashes. Next char in this case can't be a digit (0-9),
use ':' or end of line. For example:
opt_complementary = "-:w-x:x-w";
getopt32(argc, argv, "wx");
Allows any arguments to be given without a dash (./program w x)
as well as with a dash (./program -x).
"-N" A dash as the first char in a opt_complementary group followed
by a single digit (0-9) means that at least N non-option
arguments must be present on the command line
"=N" An equal sign as the first char in a opt_complementary group followed
by a single digit (0-9) means that exactly N non-option
arguments must be present on the command line
"V-" An option with dash before colon or end-of-line results in
bb_show_usage being called if this option is encountered.
This is typically used to implement "print verbose usage message
and exit" option.
"--" A double dash between two options, or between an option and a group
of options, means that they are mutually exclusive. Unlike
the "-" case above, an error will be forced if the options
@@ -221,10 +231,6 @@ Special characters:
if BB_GETOPT_ERROR is detected, don't return, call bb_show_usage
and exit instead. Next char after '?' can't be a digit.
"?N" A "?" as the first char in a opt_complementary group followed
by a single digit (0-9) means that at most N arguments must be present
on the command line.
"::" A double colon after a char in opt_complementary means that the
option can occur multiple times. Each occurrence will be saved as
a llist_t element instead of char*.
@@ -245,12 +251,6 @@ Special characters:
root:x:0:0:root:/root:/bin/bash
user:x:500:500::/home/user:/bin/bash
"--" A double dash at the beginning of opt_complementary means the
argv[1] string should always be treated as options, even if it isn't
prefixed with a "-". This is useful for special syntax in applets
such as "ar" and "tar":
tar xvf foo.tar
"?" An "?" between an option and a group of options means that
at least one of them is required to occur if the first option
occurs in preceding command line arguments.

View File

@@ -13,5 +13,5 @@
/* Busybox mount uses either /proc/mounts or /etc/mtab to
* get the list of currently mounted filesystems */
const char bb_path_mtab_file[] = USE_FEATURE_MTAB_SUPPORT("/etc/mtab")
SKIP_FEATURE_MTAB_SUPPORT("/proc/mounts");
const char bb_path_mtab_file[] =
USE_FEATURE_MTAB_SUPPORT("/etc/mtab")SKIP_FEATURE_MTAB_SUPPORT("/proc/mounts");

View File

@@ -216,39 +216,39 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags)
}
/* from kernel:
// pid comm S ppid pgid sid tty_nr tty_pgrp flg
sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
%lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
%lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu %llu\n",
task->pid,
tcomm,
state,
ppid,
pgid,
sid,
tty_nr,
tty_pgrp,
task->flags,
min_flt,
task->pid,
tcomm,
state,
ppid,
pgid,
sid,
tty_nr,
tty_pgrp,
task->flags,
min_flt,
cmin_flt,
maj_flt,
cmaj_flt,
cputime_to_clock_t(utime),
cputime_to_clock_t(stime),
cputime_to_clock_t(cutime),
cputime_to_clock_t(cstime),
priority,
nice,
num_threads,
// 0,
start_time,
vsize,
mm ? get_mm_rss(mm) : 0,
rsslim,
mm ? mm->start_code : 0,
mm ? mm->end_code : 0,
mm ? mm->start_stack : 0,
esp,
eip,
cmin_flt,
maj_flt,
cmaj_flt,
cputime_to_clock_t(utime),
cputime_to_clock_t(stime),
cputime_to_clock_t(cutime),
cputime_to_clock_t(cstime),
priority,
nice,
num_threads,
// 0,
start_time,
vsize,
mm ? get_mm_rss(mm) : 0,
rsslim,
mm ? mm->start_code : 0,
mm ? mm->end_code : 0,
mm ? mm->start_stack : 0,
esp,
eip,
the rest is some obsolete cruft
*/

View File

@@ -102,40 +102,38 @@ int safe_strtol(const char *arg, long* value)
# define strong_alias(name, aliasname) _strong_alias (name, aliasname)
# define _strong_alias(name, aliasname) \
__asm__(".global " __C_SYMBOL_PREFIX__ #aliasname "\n" \
".set " __C_SYMBOL_PREFIX__ #aliasname "," __C_SYMBOL_PREFIX__ #name);
__asm__(".global " __C_SYMBOL_PREFIX__ #aliasname "\n" \
".set " __C_SYMBOL_PREFIX__ #aliasname "," __C_SYMBOL_PREFIX__ #name);
#endif
#endif
int safe_strtoi(const char *arg, int* value)
{
if (sizeof(long) == sizeof(int)) {
int error;
long lvalue;
if (sizeof(long) == sizeof(int))
return safe_strtol(arg, (long*)value);
} else {
int error;
long lvalue = *value;
error = safe_strtol(arg, &lvalue);
if (lvalue < INT_MIN || lvalue > INT_MAX)
return 1;
*value = (int) lvalue;
return error;
}
lvalue = *value;
error = safe_strtol(arg, &lvalue);
if (lvalue < INT_MIN || lvalue > INT_MAX)
return 1;
*value = (int) lvalue;
return error;
}
int safe_strtou(const char *arg, unsigned* value)
{
if (sizeof(unsigned long) == sizeof(unsigned)) {
int error;
unsigned long lvalue;
if (sizeof(unsigned long) == sizeof(unsigned))
return safe_strtoul(arg, (unsigned long*)value);
} else {
int error;
unsigned long lvalue = *value;
error = safe_strtoul(arg, &lvalue);
if (lvalue > UINT_MAX)
return 1;
*value = (unsigned) lvalue;
return error;
}
lvalue = *value;
error = safe_strtoul(arg, &lvalue);
if (lvalue > UINT_MAX)
return 1;
*value = (unsigned) lvalue;
return error;
}
int BUG_safe_strtou32_unimplemented(void);