summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-02-07 20:04:57 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-02-07 20:04:57 +0000
commite72b5790aad72ffb83f10306115d53d3a02ab6ac (patch)
tree7967ea060af5b901b5d563f2a05c4fbdba6089d4
parent8282c0d6aa03fc4b37c554e2c347b81c84ce62d0 (diff)
downloadmandoc-e72b5790aad72ffb83f10306115d53d3a02ab6ac.tar.gz
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--mandoc_aux.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/mandoc_aux.c b/mandoc_aux.c
index 78466d95..f1dce2e8 100644
--- a/mandoc_aux.c
+++ b/mandoc_aux.c
@@ -111,8 +111,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;
}