summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreric <eric@openbsd.org>2010-04-25 14:13:36 +0000
committereric <eric@openbsd.org>2010-04-25 14:13:36 +0000
commit51098fef017c5c422572be9e806a650bf534f251 (patch)
treec6a2b05ab9b1aab8c02c5fd4617f3740c0a81758
parentpure whitespace cleanup (diff)
downloadwireguard-openbsd-51098fef017c5c422572be9e806a650bf534f251.tar.xz
wireguard-openbsd-51098fef017c5c422572be9e806a650bf534f251.zip
prevent out-of-bounds access with empty pattern (fixes "grep -x ''")
ok millert@ krw@
-rw-r--r--usr.bin/grep/util.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 39e8ea346f7..eb9da8b74ee 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.37 2010/04/05 03:03:55 tedu Exp $ */
+/* $OpenBSD: util.c,v 1.38 2010/04/25 14:13:36 eric Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -279,7 +279,7 @@ fastcomp(fastgrep_t *fg, const char *pattern)
fg->reversedSearch = 0;
/* Remove end-of-line character ('$'). */
- if (pattern[fg->patternLen - 1] == '$') {
+ if (fg->patternLen > 0 && pattern[fg->patternLen - 1] == '$') {
eol++;
fg->eol = 1;
fg->patternLen--;