diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-02-27 14:56:12 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-02-27 14:56:12 +0100 |
commit | 83e49ade5724f5b3744660e45179461fe2a1b0f8 (patch) | |
tree | 1f819a54cf2eb2955bea016c4906f70b99c1c20a /findutils/grep.c | |
parent | 6f068904dc142657bb596f91196f9113f1838cbe (diff) | |
download | busybox-w32-83e49ade5724f5b3744660e45179461fe2a1b0f8.tar.gz busybox-w32-83e49ade5724f5b3744660e45179461fe2a1b0f8.tar.bz2 busybox-w32-83e49ade5724f5b3744660e45179461fe2a1b0f8.zip |
grep: fix -w match if first match isn't a word, but second is. Closes 4520
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'findutils/grep.c')
-rw-r--r-- | findutils/grep.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index 76859464f..f1b6dc694 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -418,13 +418,15 @@ static int grep_file(FILE *file) | |||
418 | found = 1; | 418 | found = 1; |
419 | } else { | 419 | } else { |
420 | char c = ' '; | 420 | char c = ' '; |
421 | if (match_at > line || gl->matched_range.rm_so != 0) | 421 | if (match_at > line || gl->matched_range.rm_so != 0) { |
422 | c = match_at[gl->matched_range.rm_so - 1]; | 422 | c = match_at[gl->matched_range.rm_so - 1]; |
423 | } | ||
423 | if (!isalnum(c) && c != '_') { | 424 | if (!isalnum(c) && c != '_') { |
424 | c = match_at[gl->matched_range.rm_eo]; | 425 | c = match_at[gl->matched_range.rm_eo]; |
425 | if (!c || (!isalnum(c) && c != '_')) { | 426 | } |
426 | found = 1; | 427 | if (!isalnum(c) && c != '_') { |
427 | } else { | 428 | found = 1; |
429 | } else { | ||
428 | /* | 430 | /* |
429 | * Why check gl->matched_range.rm_eo? | 431 | * Why check gl->matched_range.rm_eo? |
430 | * Zero-length match makes -w skip the line: | 432 | * Zero-length match makes -w skip the line: |
@@ -433,18 +435,17 @@ static int grep_file(FILE *file) | |||
433 | * Without such check, we can loop forever. | 435 | * Without such check, we can loop forever. |
434 | */ | 436 | */ |
435 | #if !ENABLE_EXTRA_COMPAT | 437 | #if !ENABLE_EXTRA_COMPAT |
436 | if (gl->matched_range.rm_eo != 0) { | 438 | if (gl->matched_range.rm_eo != 0) { |
437 | match_at += gl->matched_range.rm_eo; | 439 | match_at += gl->matched_range.rm_eo; |
438 | match_flg |= REG_NOTBOL; | 440 | match_flg |= REG_NOTBOL; |
439 | goto opt_w_again; | 441 | goto opt_w_again; |
440 | } | 442 | } |
441 | #else | 443 | #else |
442 | if (gl->matched_range.rm_eo > start_pos) { | 444 | if (gl->matched_range.rm_eo > start_pos) { |
443 | start_pos = gl->matched_range.rm_eo; | 445 | start_pos = gl->matched_range.rm_eo; |
444 | goto opt_w_again; | 446 | goto opt_w_again; |
445 | } | ||
446 | #endif | ||
447 | } | 447 | } |
448 | #endif | ||
448 | } | 449 | } |
449 | } | 450 | } |
450 | } | 451 | } |