diff options
author | 2018-02-07 20:04:33 +0000 | |
---|---|---|
committer | 2018-02-07 20:04:33 +0000 | |
commit | 2dfc6a663df73e38907826fd8aac3aad7d581ad4 (patch) | |
tree | 886c2319ef8f2622445e91d62446a27843ff8cc7 | |
parent | fix wrong date (diff) | |
download | wireguard-openbsd-2dfc6a663df73e38907826fd8aac3aad7d581ad4.tar.xz wireguard-openbsd-2dfc6a663df73e38907826fd8aac3aad7d581ad4.zip |
Fix the mandoc_strndup() utility function. All existing callers seem
safe so far, but implementing it with an unchecked memcpy(3) is just
wrong and quite dangerous.
-rw-r--r-- | usr.bin/mandoc/mandoc_aux.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/usr.bin/mandoc/mandoc_aux.c b/usr.bin/mandoc/mandoc_aux.c index 6fa396a7909..7c23ecfdd01 100644 --- a/usr.bin/mandoc/mandoc_aux.c +++ b/usr.bin/mandoc/mandoc_aux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc_aux.c,v 1.8 2017/06/12 18:55:42 schwarze Exp $ */ +/* $OpenBSD: mandoc_aux.c,v 1.9 2018/02/07 20:04:33 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -106,8 +106,8 @@ mandoc_strndup(const char *ptr, size_t sz) { char *p; - p = mandoc_malloc(sz + 1); - memcpy(p, ptr, sz); - p[(int)sz] = '\0'; + p = strndup(ptr, sz); + if (p == NULL) + err((int)MANDOCLEVEL_SYSERR, NULL); return p; } |