diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2018-02-07 20:04:57 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2018-02-07 20:04:57 +0000 |
commit | e72b5790aad72ffb83f10306115d53d3a02ab6ac (patch) | |
tree | 7967ea060af5b901b5d563f2a05c4fbdba6089d4 | |
parent | 8282c0d6aa03fc4b37c554e2c347b81c84ce62d0 (diff) | |
download | mandoc-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.c | 6 |
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; } |