From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id f71fed4a for ; Wed, 7 Feb 2018 15:05:27 -0500 (EST) Date: Wed, 7 Feb 2018 15:05:27 -0500 (EST) X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: mandoc: Fix the mandoc_strndup() utility function. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-Id: <84f49340b4bf452d@fantadrom.bsd.lv> 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