Commit 7c57899b authored by Sören Tempel's avatar Sören Tempel

main/busybox: backport proper pattern_list support for busybox

Even though this patch was written by myself it was already included
upstream. I find this issues to be particularly annoying as my mail
client (community/mblaze) uses this feature and who known how long until
busybox 1.32.0 is released.
parent 7a73da89
Pipeline #20829 passed with stages
in 4 minutes and 17 seconds
From 42a8984abc5eed709addac263aab43d64d47257d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
Date: Mon, 30 Mar 2020 11:02:08 +0200
Subject: [PATCH] grep: add proper support for pattern_list
From POSIX.1-2008:
The pattern_list's value shall consist of one or more patterns
separated by <newline> characters;
As such, given patterns need to be split at newline characters. Without
doing so, busybox grep will interpret the newline as part of the pattern
which is not in accordance with POSIX.
See also: https://bugs.busybox.net/show_bug.cgi?id=12721
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
findutils/grep.c | 19 +++++++++++++------
testsuite/grep.tests | 12 ++++++++++++
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/findutils/grep.c b/findutils/grep.c
index 84a6f7b1c..55e9c0a8f 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -650,6 +650,13 @@ static void load_regexes_from_file(llist_t *fopt)
}
}
+static void load_pattern_list(llist_t **lst, char *pattern)
+{
+ char *p;
+ while ((p = strsep(&pattern, "\n")) != NULL)
+ llist_add_to(lst, new_grep_list_data(p, 0));
+}
+
static int FAST_FUNC file_action_grep(const char *filename,
struct stat *statbuf,
void* matched,
@@ -754,10 +761,12 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
#endif
invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */
- { /* convert char **argv to grep_list_data_t */
- llist_t *cur;
+ { /* convert char **argv to pattern_list */
+ llist_t *cur, *new = NULL;
for (cur = pattern_head; cur; cur = cur->link)
- cur->data = new_grep_list_data(cur->data, 0);
+ load_pattern_list(&new, cur->data);
+ llist_free(pattern_head, NULL);
+ pattern_head = new;
}
if (option_mask32 & OPT_f) {
load_regexes_from_file(fopt);
@@ -806,11 +815,9 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
/* if we didn't get a pattern from -e and no command file was specified,
* first parameter should be the pattern. no pattern, no worky */
if (pattern_head == NULL) {
- char *pattern;
if (*argv == NULL)
bb_show_usage();
- pattern = new_grep_list_data(*argv++, 0);
- llist_add_to(&pattern_head, pattern);
+ load_pattern_list(&pattern_head, *argv++);
}
/* argv[0..(argc-1)] should be names of file to grep through. If
diff --git a/testsuite/grep.tests b/testsuite/grep.tests
index 9c1f35499..e38278810 100755
--- a/testsuite/grep.tests
+++ b/testsuite/grep.tests
@@ -190,6 +190,18 @@ testing "grep -x -v -e EXP1 -e EXP2 finds nothing if either EXP matches" \
"" \
" aa bb cc\n"
+testing "grep PATTERN can be a newline-delimited list" \
+ 'grep -Fv "$(printf "foo\nbar\n")"' \
+ "baz\n" \
+ "" \
+ "foo\nbar\nbaz\n"
+
+testing "grep -e PATTERN can be a newline-delimited list" \
+ 'grep -Fv -e "$(printf "foo\nbar\n")"' \
+ "baz\n" \
+ "" \
+ "foo\nbar\nbaz\n"
+
# -r on symlink to dir should recurse into dir
mkdir -p grep.testdir/foo
echo bar > grep.testdir/foo/file
......@@ -3,7 +3,7 @@
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=busybox
pkgver=1.31.1
pkgrel=16
pkgrel=17
pkgdesc="Size optimized toolbox of many common UNIX utilities"
url="https://busybox.net/"
arch="all"
......@@ -19,6 +19,7 @@ options="suid !check"
replaces="busybox-initscripts" # move of default.script
triggers="busybox.trigger=/bin:/usr/bin:/sbin:/usr/sbin:/lib/modules/*"
source="https://busybox.net/downloads/busybox-$pkgver.tar.bz2
0001-grep-add-proper-support-for-pattern_list.patch
0001-ln-no-target-directory-implies-no-dereference.patch
0001-nologin-Install-applet-to-sbin-instead-of-usr-sbin.patch
0001-adduser-default-to-sbin-nologin-as-shell-for-system-.patch
......@@ -213,6 +214,7 @@ ssl_client() {
sha512sums="0d1197c25d963d7f95ef21e08c06c0d6124ac7b59c99989e891f744ffee4878a3b1fe44a247241a9da39fa5de0ba87f1b6d862401b591f277e66e89c02764bbf busybox-1.31.1.tar.bz2
7ab971e18c2bde30332817d989d87fa9350c650ddc7186b2450f2f946cc4f583d993015fa244860a24bfaca1bb50d59d1da9bb8276656f056059a078c9ce3f02 0001-grep-add-proper-support-for-pattern_list.patch
07e79138c80a12fd3c8770c4a1beaba986465b099816511d2de744b34f7457f22351d991f510cce8665effd651cca34a85f685ed52747313b3980ebf25988958 0001-ln-no-target-directory-implies-no-dereference.patch
ead3403578c071c2216de17ab0543984c1f1509c12c062f03af49141547c3ea21356f3e8f0f0695550f05a41a1379dd73fc3cc18dcd78addbb411f247351e353 0001-nologin-Install-applet-to-sbin-instead-of-usr-sbin.patch
a2787a3ecaf6746dadef62166e8ee6ecaa166147e5ad8b917c5838536057c875bab5f9cf40c3e05eba74d575484ac662929ac3799d58432d3a99ac46f364f302 0001-adduser-default-to-sbin-nologin-as-shell-for-system-.patch
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment