From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: Fix the mandoc_strndup() utility function.
Date: Wed, 7 Feb 2018 15:05:27 -0500 (EST) [thread overview]
Message-ID: <84f49340b4bf452d@fantadrom.bsd.lv> (raw)
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
reply other threads:[~2018-02-07 20:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=84f49340b4bf452d@fantadrom.bsd.lv \
--to=schwarze@mandoc.bsd.lv \
--cc=source@mandoc.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).