aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-09-26 18:25:54 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-09-26 18:25:54 +0000
commit668ee1016865dcde796cc57b1c1e7c35b85f41d1 (patch)
treea05a3c6852619135d6f9761144b9a87827733056 /usr.bin
parent6b3555c38ee5fc01ab4cd6ef4ad73b0854b0dc62 (diff)
parente12ff891366cf94db4bfe4c2c810b26a5531053d (diff)
Notes
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/bsdiff/bspatch/bspatch.c35
-rw-r--r--usr.bin/grep/grep.c27
-rw-r--r--usr.bin/grep/util.c37
-rw-r--r--usr.bin/kdump/kdump.c4
-rw-r--r--usr.bin/truss/syscalls.c2
5 files changed, 66 insertions, 39 deletions
diff --git a/usr.bin/bsdiff/bspatch/bspatch.c b/usr.bin/bsdiff/bspatch/bspatch.c
index 688962576f4c..6c9656486394 100644
--- a/usr.bin/bsdiff/bspatch/bspatch.c
+++ b/usr.bin/bsdiff/bspatch/bspatch.c
@@ -61,6 +61,23 @@ exit_cleanup(void)
warn("unlinkat");
}
+static inline off_t
+add_off_t(off_t a, off_t b)
+{
+ off_t result;
+
+#if __GNUC__ >= 5 || \
+ (defined(__has_builtin) && __has_builtin(__builtin_add_overflow))
+ if (__builtin_add_overflow(a, b, &result))
+ errx(1, "Corrupt patch");
+#else
+ if ((b > 0 && a > OFF_MAX - b) || (b < 0 && a < OFF_MIN - b))
+ errx(1, "Corrupt patch");
+ result = a + b;
+#endif
+ return result;
+}
+
static off_t offtin(u_char *buf)
{
off_t y;
@@ -199,12 +216,12 @@ int main(int argc, char *argv[])
err(1, "fseeko(%s, %jd)", argv[3], (intmax_t)offset);
if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err);
- offset += bzctrllen;
+ offset = add_off_t(offset, bzctrllen);
if (fseeko(dpf, offset, SEEK_SET))
err(1, "fseeko(%s, %jd)", argv[3], (intmax_t)offset);
if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err);
- offset += bzdatalen;
+ offset = add_off_t(offset, bzdatalen);
if (fseeko(epf, offset, SEEK_SET))
err(1, "fseeko(%s, %jd)", argv[3], (intmax_t)offset);
if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL)
@@ -238,7 +255,7 @@ int main(int argc, char *argv[])
errx(1, "Corrupt patch");
/* Sanity-check */
- if (newpos + ctrl[0] > newsize)
+ if (add_off_t(newpos, ctrl[0]) > newsize)
errx(1, "Corrupt patch");
/* Read diff string */
@@ -249,15 +266,15 @@ int main(int argc, char *argv[])
/* Add old data to diff string */
for (i = 0; i < ctrl[0]; i++)
- if ((oldpos + i >= 0) && (oldpos + i < oldsize))
+ if (add_off_t(oldpos, i) < oldsize)
new[newpos + i] += old[oldpos + i];
/* Adjust pointers */
- newpos += ctrl[0];
- oldpos += ctrl[0];
+ newpos = add_off_t(newpos, ctrl[0]);
+ oldpos = add_off_t(oldpos, ctrl[0]);
/* Sanity-check */
- if (newpos + ctrl[1] > newsize)
+ if (add_off_t(newpos, ctrl[1]) > newsize)
errx(1, "Corrupt patch");
/* Read extra string */
@@ -267,8 +284,8 @@ int main(int argc, char *argv[])
errx(1, "Corrupt patch");
/* Adjust pointers */
- newpos+=ctrl[1];
- oldpos+=ctrl[2];
+ newpos = add_off_t(newpos, ctrl[1]);
+ oldpos = add_off_t(oldpos, ctrl[2]);
}
/* Clean up the bzip2 reads */
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index 20911c294343..731e46bb112e 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -218,20 +218,9 @@ static void
add_pattern(char *pat, size_t len)
{
- /* Do not add further pattern is we already match everything */
- if (matchall)
- return;
-
/* Check if we can do a shortcut */
if (len == 0) {
matchall = true;
- for (unsigned int i = 0; i < patterns; i++) {
- free(pattern[i].pat);
- }
- pattern = grep_realloc(pattern, sizeof(struct pat));
- pattern[0].pat = NULL;
- pattern[0].len = 0;
- patterns = 1;
return;
}
/* Increase size if necessary */
@@ -654,7 +643,7 @@ main(int argc, char *argv[])
aargv += optind;
/* Empty pattern file matches nothing */
- if (!needpattern && (patterns == 0))
+ if (!needpattern && (patterns == 0) && !matchall)
exit(1);
/* Fail if we don't have any pattern */
@@ -701,11 +690,10 @@ main(int argc, char *argv[])
r_pattern = grep_calloc(patterns, sizeof(*r_pattern));
- /* Don't process any patterns if we have a blank one */
#ifdef WITH_INTERNAL_NOSPEC
- if (!matchall && grepbehave != GREP_FIXED) {
+ if (grepbehave != GREP_FIXED) {
#else
- if (!matchall) {
+ {
#endif
/* Check if cheating is allowed (always is for fgrep). */
for (i = 0; i < patterns; ++i) {
@@ -737,7 +725,12 @@ main(int argc, char *argv[])
matched = true;
}
- /* Find out the correct return value according to the
- results and the command line option. */
+ if (Lflag)
+ matched = !matched;
+
+ /*
+ * Calculate the correct return value according to the
+ * results and the command line option.
+ */
exit(matched ? (file_err ? (qflag ? 0 : 2) : 0) : (file_err ? 2 : 1));
}
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 07d9b40cbdcd..33afe4d6b030 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -210,7 +210,7 @@ procmatch_match(struct mprintc *mc, struct parsec *pc)
while (pc->matchidx >= MAX_MATCHES) {
/* Reset matchidx and try again */
pc->matchidx = 0;
- if (procline(pc))
+ if (procline(pc) == !vflag)
printline(pc, ':');
else
break;
@@ -355,7 +355,7 @@ procfile(const char *fn)
return (0);
}
- line_matched = procline(&pc);
+ line_matched = procline(&pc) == !vflag;
if (line_matched)
++lines;
@@ -469,17 +469,32 @@ procline(struct parsec *pc)
matchidx = pc->matchidx;
- /* Special case: empty pattern with -w flag, check first character */
- if (matchall && wflag) {
+ /*
+ * With matchall (empty pattern), we can try to take some shortcuts.
+ * Emtpy patterns trivially match every line except in the -w and -x
+ * cases. For -w (whole-word) cases, we only match if the first
+ * character isn't a word-character. For -x (whole-line) cases, we only
+ * match if the line is empty.
+ */
+ if (matchall) {
if (pc->ln.len == 0)
return (true);
- wend = L' ';
- if (sscanf(&pc->ln.dat[0], "%lc", &wend) != 1 || iswword(wend))
- return (false);
- else
+ if (wflag) {
+ wend = L' ';
+ if (sscanf(&pc->ln.dat[0], "%lc", &wend) == 1 &&
+ !iswword(wend))
+ return (true);
+ } else if (!xflag)
return (true);
- } else if (matchall)
- return (true);
+
+ /*
+ * If we don't have any other patterns, we really don't match.
+ * If we do have other patterns, we must fall through and check
+ * them.
+ */
+ if (patterns == 0)
+ return (false);
+ }
matched = false;
st = pc->lnstart;
@@ -609,8 +624,6 @@ procline(struct parsec *pc)
/* Reflect the new matchidx in the context */
pc->matchidx = matchidx;
- if (vflag)
- matched = !matched;
return matched;
}
diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c
index 25b2508f862f..3319d2f06607 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -1246,7 +1246,8 @@ ktrsyscall(struct ktr_syscall *ktr, u_int sv_flags)
ip++;
narg--;
break;
- case SYS_shm_open:
+#ifdef SYS_freebsd12_shm_open
+ case SYS_freebsd12_shm_open:
print_number(ip, narg, c);
putchar(',');
print_mask_arg(sysdecode_open_flags, ip[0]);
@@ -1255,6 +1256,7 @@ ktrsyscall(struct ktr_syscall *ktr, u_int sv_flags)
ip += 2;
narg -= 2;
break;
+#endif
case SYS_minherit:
print_number(ip, narg, c);
print_number(ip, narg, c);
diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c
index e6a1fbd21bf8..e06a818b721f 100644
--- a/usr.bin/truss/syscalls.c
+++ b/usr.bin/truss/syscalls.c
@@ -471,6 +471,8 @@ static struct syscall decoded_syscalls[] = {
{ Ptr | IN, 3 }, { Socklent, 4 } } },
{ .name = "shm_open", .ret_type = 1, .nargs = 3,
.args = { { ShmName | IN, 0 }, { Open, 1 }, { Octal, 2 } } },
+ { .name = "shm_rename", .ret_type = 1, .nargs = 3,
+ .args = { { Name | IN, 0 }, { Name | IN, 1 }, { Hex, 2 } } },
{ .name = "shm_unlink", .ret_type = 1, .nargs = 1,
.args = { { Name | IN, 0 } } },
{ .name = "shutdown", .ret_type = 1, .nargs = 2,