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 | a01d965c76db9cf227d69d8316586f39cd940ab1 (patch) | |
tree | f5c9d03b7ad3883a2215a20b922a54edab62a699 | |
parent | 6cf85d647d2389577407d50b04f4a760c1eed882 (diff) | |
download | mandoc-a01d965c76db9cf227d69d8316586f39cd940ab1.tar.gz mandoc-a01d965c76db9cf227d69d8316586f39cd940ab1.tar.zst mandoc-a01d965c76db9cf227d69d8316586f39cd940ab1.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-- | mandoc_aux.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/mandoc_aux.c b/mandoc_aux.c index db593e44..5d595ce0 100644 --- a/mandoc_aux.c +++ b/mandoc_aux.c @@ -1,4 +1,4 @@ -/* $Id: mandoc_aux.c,v 1.10 2017/06/12 19:05:47 schwarze Exp $ */ +/* $Id: mandoc_aux.c,v 1.11 2018/02/07 20:04:57 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -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; } |