summaryrefslogtreecommitdiffstats
path: root/usr.bin/grep/grep.c
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2003-06-23 22:32:48 +0000
committertedu <tedu@openbsd.org>2003-06-23 22:32:48 +0000
commit4d90a27a7bef2a33f3f003f4dd96ccb4c49d20e0 (patch)
treeb06a500b7817a46228e0b080946729343e9b4730 /usr.bin/grep/grep.c
parentgo back to using strncpy. for long patterns, strlcpy reads too much (diff)
downloadwireguard-openbsd-4d90a27a7bef2a33f3f003f4dd96ccb4c49d20e0.tar.xz
wireguard-openbsd-4d90a27a7bef2a33f3f003f4dd96ccb4c49d20e0.zip
strncpy -> memcpy per deraadt suggestion.
also add a note why we can't use strlcpy.
Diffstat (limited to 'usr.bin/grep/grep.c')
-rw-r--r--usr.bin/grep/grep.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index c7abfc35e3a..3fce875d9a5 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.c,v 1.14 2003/06/23 22:27:09 tedu Exp $ */
+/* $OpenBSD: grep.c,v 1.15 2003/06/23 22:32:48 tedu Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -171,7 +171,8 @@ add_pattern(char *pat, size_t len)
if (pat[len - 1] == '\n')
--len;
pattern[patterns] = grep_malloc(len + 1);
- strncpy(pattern[patterns], pat, len);
+ /* pat may not be NUL-terminated */
+ memcpy(pattern[patterns], pat, len);
pattern[patterns][len] = '\0';
++patterns;