From e72b5790aad72ffb83f10306115d53d3a02ab6ac Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Wed, 7 Feb 2018 20:04:57 +0000 Subject: 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. --- mandoc_aux.c | 6 +++--- 1 file 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; } -- cgit