Page MenuHomeFreeBSD

D10675.id28223.diff
No OneTemporary

D10675.id28223.diff

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

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)

Event Timeline