summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenis Vlasenko2007-05-08 17:27:17 +0000
committerDenis Vlasenko2007-05-08 17:27:17 +0000
commit92c0b8222eb50dd35c06e2f1265706b388762234 (patch)
treec94def6f5c4cfbbcc1a7a70d96e721eb433ed01f /coreutils
parent0cacc80952a7a34f9cb8b384d6dd0b1522c37bae (diff)
downloadbusybox-92c0b8222eb50dd35c06e2f1265706b388762234.zip
busybox-92c0b8222eb50dd35c06e2f1265706b388762234.tar.gz
tail: fix SEGV on "tail -N"
config system: clarify PREFER_APPLETS/SH_STANDALONE effects in help text
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/tail.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 629ee21..32df259 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -79,7 +79,8 @@ int tail_main(int argc, char **argv)
unsigned sleep_period = 1;
bool from_top;
int header_threshhold = 1;
- const char *str_c, *str_n, *str_s;
+ const char *str_c, *str_n;
+ USE_FEATURE_FANCY_TAIL(const char *str_s;)
char *tailbuf;
size_t tailbufsize;
@@ -96,13 +97,18 @@ int tail_main(int argc, char **argv)
if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-')
&& isdigit(argv[1][1])
) {
- argv[0] = (char*)"-n";
- argv--;
- argc++;
+ /* replacing arg[0] with "-n" can segfault, so... */
+ argv[1] = xasprintf("-n%s", argv[1]);
+#if 0 /* If we ever decide to make tail NOFORK */
+ char *s = alloca(strlen(argv[1]) + 3);
+ sprintf(s, "-n%s", argv[1]);
+ argv[1] = s;
+#endif
}
#endif
- opt = getopt32(argc, argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"), &str_c, &str_n, &str_s);
+ opt = getopt32(argc, argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"),
+ &str_c, &str_n USE_FEATURE_FANCY_TAIL(,&str_s));
#define FOLLOW (opt & 0x1)
#define COUNT_BYTES (opt & 0x2)
//if (opt & 0x1) // -f