aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-05-08 17:27:17 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-05-08 17:27:17 +0000
commit92ce299856803ce2a2e59c4bfd2cc9edce90d3f7 (patch)
treec94def6f5c4cfbbcc1a7a70d96e721eb433ed01f /coreutils
parentfc24e2de044defa5e26e99a125dc2b361cab184a (diff)
downloadbusybox-w32-92ce299856803ce2a2e59c4bfd2cc9edce90d3f7.tar.gz
busybox-w32-92ce299856803ce2a2e59c4bfd2cc9edce90d3f7.tar.bz2
busybox-w32-92ce299856803ce2a2e59c4bfd2cc9edce90d3f7.zip
tail: fix SEGV on "tail -N"
config system: clarify PREFER_APPLETS/SH_STANDALONE effects in help text git-svn-id: svn://busybox.net/trunk/busybox@18585 69ca8d6d-28ef-0310-b511-8ec308f3f277
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 629ee2125..32df25914 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -79,7 +79,8 @@ int tail_main(int argc, char **argv)
79 unsigned sleep_period = 1; 79 unsigned sleep_period = 1;
80 bool from_top; 80 bool from_top;
81 int header_threshhold = 1; 81 int header_threshhold = 1;
82 const char *str_c, *str_n, *str_s; 82 const char *str_c, *str_n;
83 USE_FEATURE_FANCY_TAIL(const char *str_s;)
83 84
84 char *tailbuf; 85 char *tailbuf;
85 size_t tailbufsize; 86 size_t tailbufsize;
@@ -96,13 +97,18 @@ int tail_main(int argc, char **argv)
96 if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-') 97 if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-')
97 && isdigit(argv[1][1]) 98 && isdigit(argv[1][1])
98 ) { 99 ) {
99 argv[0] = (char*)"-n"; 100 /* replacing arg[0] with "-n" can segfault, so... */
100 argv--; 101 argv[1] = xasprintf("-n%s", argv[1]);
101 argc++; 102#if 0 /* If we ever decide to make tail NOFORK */
103 char *s = alloca(strlen(argv[1]) + 3);
104 sprintf(s, "-n%s", argv[1]);
105 argv[1] = s;
106#endif
102 } 107 }
103#endif 108#endif
104 109
105 opt = getopt32(argc, argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"), &str_c, &str_n, &str_s); 110 opt = getopt32(argc, argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"),
111 &str_c, &str_n USE_FEATURE_FANCY_TAIL(,&str_s));
106#define FOLLOW (opt & 0x1) 112#define FOLLOW (opt & 0x1)
107#define COUNT_BYTES (opt & 0x2) 113#define COUNT_BYTES (opt & 0x2)
108 //if (opt & 0x1) // -f 114 //if (opt & 0x1) // -f