summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2018-02-07 20:04:34 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2018-02-07 20:04:34 +0000
commit88984196776bd9535df901f10db857393b97f7cd (patch)
tree42d5919d94373ba5546cf61b73a38dd64f509033 /usr.bin
parent16623658308916cc4e49e34404cbb35c29a3c9d9 (diff)
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.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/mandoc_aux.c8
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;
}