source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: Fix the mandoc_strndup() utility function.
@ 2018-02-07 20:05 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2018-02-07 20:05 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-02-07 20:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-07 20:05 mandoc: Fix the mandoc_strndup() utility function schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).