aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-04-23 16:08:33 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-04-23 16:08:33 +0000
commite1bb09be17d41880b391cdcbe9d968f8964928ff (patch)
treeeeb097d0331817dc1ea9f7b52f2930635bda4387 /mdoc_validate.c
parent1f555653eb03957679b5749f7ac779126c3c2627 (diff)
downloadmandoc-e1bb09be17d41880b391cdcbe9d968f8964928ff.tar.gz
mandoc-e1bb09be17d41880b391cdcbe9d968f8964928ff.tar.zst
mandoc-e1bb09be17d41880b391cdcbe9d968f8964928ff.zip
Audit strlcpy(3)/strlcat(3) usage.
* Repair three instances of silent truncation, use asprintf(3). * Change two instances of strlen(3)+malloc(3)+strlcpy(3)+strlcat(3)+... to use asprintf(3) instead to make them less error prone. * Cast the return value of four instances where the destination buffer is known to be large enough to (void). * Completely remove three useless instances of strlcpy(3)/strlcat(3). * Mark two places in -Thtml with XXX that can cause information loss and crashes but are not easy to fix, requiring design changes of some internal interfaces. * The file mandocdb.c remains to be audited.
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 55573fa8..8c394328 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.212 2014/04/20 20:48:53 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.213 2014/04/23 16:08:33 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -1183,9 +1183,9 @@ post_defaults(POST_ARGS)
static int
post_at(POST_ARGS)
{
- const char *p, *q;
- char *buf;
- size_t sz;
+ struct mdoc_node *n;
+ const char *std_att;
+ char *att;
/*
* If we have a child, look it up in the standard keys. If a
@@ -1193,27 +1193,18 @@ post_at(POST_ARGS)
* prefix "AT&T UNIX " to the existing data.
*/
- if (NULL == mdoc->last->child)
+ if (NULL == (n = mdoc->last->child))
return(1);
- assert(MDOC_TEXT == mdoc->last->child->type);
- p = mdoc_a2att(mdoc->last->child->string);
-
- if (p) {
- free(mdoc->last->child->string);
- mdoc->last->child->string = mandoc_strdup(p);
- } else {
+ assert(MDOC_TEXT == n->type);
+ if (NULL == (std_att = mdoc_a2att(n->string))) {
mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADATT);
- p = "AT&T UNIX ";
- q = mdoc->last->child->string;
- sz = strlen(p) + strlen(q) + 1;
- buf = mandoc_malloc(sz);
- strlcpy(buf, p, sz);
- strlcat(buf, q, sz);
- free(mdoc->last->child->string);
- mdoc->last->child->string = buf;
- }
+ mandoc_asprintf(&att, "AT&T UNIX %s", n->string);
+ } else
+ att = mandoc_strdup(std_att);
+ free(n->string);
+ n->string = att;
return(1);
}