[prev in list] [next in list] [prev in thread] [next in thread]
List: mandoc-source
Subject: mandoc: Fix the mandoc_strndup() utility function.
From: schwarze () mandoc ! bsd ! lv
Date: 2018-02-07 20:05:27
Message-ID: 84f49340b4bf452d () fantadrom ! bsd ! lv
[Download RAW message or body]
Log Message:
-----------
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.
Modified Files:
--------------
mandoc:
mandoc_aux.c
Revision Data
-------------
Index: mandoc_aux.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc_aux.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lmandoc_aux.c -Lmandoc_aux.c -u -p -r1.10 -r1.11
--- mandoc_aux.c
+++ mandoc_aux.c
@@ -111,8 +111,8 @@ mandoc_strndup(const char *ptr, size_t s
{
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;
}
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic