aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-10-02 12:42:28 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-10-02 12:42:28 +0200
commit0296fd3af1cb3f9cceabc31dd39b6a00b66cb65d (patch)
tree6fb4afdde40be52d395bb77198f15417f6839f6a
parent2d1a78b88f6c986cbe147fc6f99091fd61f3bdd9 (diff)
downloadbusybox-w32-0296fd3af1cb3f9cceabc31dd39b6a00b66cb65d.tar.gz
busybox-w32-0296fd3af1cb3f9cceabc31dd39b6a00b66cb65d.tar.bz2
busybox-w32-0296fd3af1cb3f9cceabc31dd39b6a00b66cb65d.zip
grep: cap insane -B NUM values to MAX_INT / 8. Fixes bug 2653.
function old new delta grep_main 766 779 +13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/grep.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index 024f27609..ff6742a69 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -621,30 +621,33 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
621 621
622 /* do normal option parsing */ 622 /* do normal option parsing */
623#if ENABLE_FEATURE_GREP_CONTEXT 623#if ENABLE_FEATURE_GREP_CONTEXT
624 int Copt; 624 int Copt, opts;
625 625
626 /* -H unsets -h; -C unsets -A,-B; -e,-f are lists; 626 /* -H unsets -h; -C unsets -A,-B; -e,-f are lists;
627 * -m,-A,-B,-C have numeric param */ 627 * -m,-A,-B,-C have numeric param */
628 opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+"; 628 opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+";
629 getopt32(argv, 629 opts = getopt32(argv,
630 OPTSTR_GREP, 630 OPTSTR_GREP,
631 &pattern_head, &fopt, &max_matches, 631 &pattern_head, &fopt, &max_matches,
632 &lines_after, &lines_before, &Copt); 632 &lines_after, &lines_before, &Copt);
633 633
634 if (option_mask32 & OPT_C) { 634 if (opts & OPT_C) {
635 /* -C unsets prev -A and -B, but following -A or -B 635 /* -C unsets prev -A and -B, but following -A or -B
636 may override it */ 636 may override it */
637 if (!(option_mask32 & OPT_A)) /* not overridden */ 637 if (!(opts & OPT_A)) /* not overridden */
638 lines_after = Copt; 638 lines_after = Copt;
639 if (!(option_mask32 & OPT_B)) /* not overridden */ 639 if (!(opts & OPT_B)) /* not overridden */
640 lines_before = Copt; 640 lines_before = Copt;
641 } 641 }
642 /* sanity checks */ 642 /* sanity checks */
643 if (option_mask32 & (OPT_c|OPT_q|OPT_l|OPT_L)) { 643 if (opts & (OPT_c|OPT_q|OPT_l|OPT_L)) {
644 option_mask32 &= ~OPT_n; 644 option_mask32 &= ~OPT_n;
645 lines_before = 0; 645 lines_before = 0;
646 lines_after = 0; 646 lines_after = 0;
647 } else if (lines_before > 0) { 647 } else if (lines_before > 0) {
648 if (lines_before > INT_MAX / sizeof(long long))
649 lines_before = INT_MAX / sizeof(long long);
650 /* overflow in (lines_before * sizeof(x)) is prevented (above) */
648 before_buf = xzalloc(lines_before * sizeof(before_buf[0])); 651 before_buf = xzalloc(lines_before * sizeof(before_buf[0]));
649 IF_EXTRA_COMPAT(before_buf_size = xzalloc(lines_before * sizeof(before_buf_size[0]));) 652 IF_EXTRA_COMPAT(before_buf_size = xzalloc(lines_before * sizeof(before_buf_size[0]));)
650 } 653 }