Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F132275183
D10675.id28223.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D10675.id28223.diff
View Options
Index: contrib/netbsd-tests/usr.bin/grep/t_grep.sh
===================================================================
--- contrib/netbsd-tests/usr.bin/grep/t_grep.sh
+++ contrib/netbsd-tests/usr.bin/grep/t_grep.sh
@@ -522,6 +522,28 @@
atf_check -o empty grep -q -A 1 -e "B" test1
atf_check -o empty grep -q -C 1 -e "B" test1
}
+
+atf_test_case badcontext
+badcontext_head()
+{
+ atf_set "descr" "Check for handling of invalid context arguments"
+}
+badcontext_body()
+{
+ printf "A\nB\nC\n" > test1
+
+ atf_check -s not-exit:0 -e ignore grep -A "-1" "B" test1
+
+ atf_check -s not-exit:0 -e ignore grep -B "-1" "B" test1
+
+ atf_check -s not-exit:0 -e ignore grep -C "-1" "B" test1
+
+ atf_check -s not-exit:0 -e ignore grep -A "B" "B" test1
+
+ atf_check -s not-exit:0 -e ignore grep -B "B" "B" test1
+
+ atf_check -s not-exit:0 -e ignore grep -C "B" "B" test1
+}
# End FreeBSD
atf_init_test_cases()
@@ -556,5 +578,6 @@
atf_add_test_case egrep_sanity
atf_add_test_case grep_sanity
atf_add_test_case grep_nomatch_flags
+ atf_add_test_case badcontext
# End FreeBSD
}
Index: usr.bin/grep/grep.h
===================================================================
--- usr.bin/grep/grep.h
+++ usr.bin/grep/grep.h
@@ -115,7 +115,7 @@
bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag,
qflag, sflag, vflag, wflag, xflag;
extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
-extern unsigned long long Aflag, Bflag;
+extern long long Aflag, Bflag;
extern long long mcount;
extern long long mlimit;
extern char fileeol;
Index: usr.bin/grep/grep.c
===================================================================
--- usr.bin/grep/grep.c
+++ usr.bin/grep/grep.c
@@ -108,8 +108,8 @@
char re_error[RE_ERROR_BUF + 1];
/* Command-line flags */
-unsigned long long Aflag; /* -A x: print x lines trailing each match */
-unsigned long long Bflag; /* -B x: print x lines leading each match */
+long long Aflag; /* -A x: print x lines trailing each match */
+long long Bflag; /* -B x: print x lines leading each match */
bool Hflag; /* -H: always print file name */
bool Lflag; /* -L: only show names of files with no matches */
bool bflag; /* -b: show block numbers for each match */
@@ -351,7 +351,7 @@
char **aargv, **eargv, *eopts;
char *ep;
const char *pn;
- unsigned long long l;
+ long long l;
unsigned int aargc, eargc, i;
int c, lastc, needpattern, newarg, prevoptind;
@@ -438,11 +438,12 @@
case '5': case '6': case '7': case '8': case '9':
if (newarg || !isdigit(lastc))
Aflag = 0;
- else if (Aflag > LLONG_MAX / 10) {
+ Aflag = Bflag = (Aflag * 10) + (c - '0');
+ /* Overflow */
+ if (Aflag < 0) {
errno = ERANGE;
err(2, NULL);
}
- Aflag = Bflag = (Aflag * 10) + (c - '0');
break;
case 'C':
if (optarg == NULL) {
@@ -454,14 +455,15 @@
/* FALLTHROUGH */
case 'B':
errno = 0;
- l = strtoull(optarg, &ep, 10);
- if (((errno == ERANGE) && (l == ULLONG_MAX)) ||
+ l = strtoll(optarg, &ep, 10);
+ if (((errno == ERANGE) && (l == LLONG_MAX)) ||
((errno == EINVAL) && (l == 0)))
err(2, NULL);
- else if (ep[0] != '\0') {
+ else if (ep[0] != '\0' || l < 0) {
errno = EINVAL;
err(2, NULL);
}
+
if (c == 'A')
Aflag = l;
else if (c == 'B')
Index: usr.bin/grep/queue.c
===================================================================
--- usr.bin/grep/queue.c
+++ usr.bin/grep/queue.c
@@ -49,7 +49,7 @@
};
static STAILQ_HEAD(, qentry) queue = STAILQ_HEAD_INITIALIZER(queue);
-static unsigned long long count;
+static long long count;
static struct qentry *dequeue(void);
Index: usr.bin/grep/util.c
===================================================================
--- usr.bin/grep/util.c
+++ usr.bin/grep/util.c
@@ -196,11 +196,12 @@
procfile(const char *fn)
{
struct parsec pc;
+ long long tail;
struct file *f;
struct stat sb;
struct str *ln;
mode_t s;
- int c, last_outed, t, tail;
+ int c, last_outed, t;
bool doctx, printmatch, same_file;
if (strcmp(fn, "-") == 0) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 16, 10:24 AM (4 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
23789038
Default Alt Text
D10675.id28223.diff (3 KB)
Attached To
Mode
D10675: bsdgrep(1): Don't allow negative -A/-B/-C
Attached
Detach File
Event Timeline
Log In to Comment