aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/man_term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-04-20 20:18:12 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-04-20 20:18:12 +0000
commitfece5afe88597138c5b8649d9a19911461e3622b (patch)
tree673903aa78a85c00d4d4169be13b68808d419833 /man_term.c
parentc0c47ffe49a70fb77831194f625f593bd29c449e (diff)
downloadmandoc-fece5afe88597138c5b8649d9a19911461e3622b.tar.gz
mandoc-fece5afe88597138c5b8649d9a19911461e3622b.tar.zst
mandoc-fece5afe88597138c5b8649d9a19911461e3622b.zip
fix unchecked snprintf(3) in page header printing:
the length of the title is unknown, and speed doesn't matter here, so use asprintf/free rather than a static buffer
Diffstat (limited to 'man_term.c')
-rw-r--r--man_term.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/man_term.c b/man_term.c
index 9aab4707..f3fc4114 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.146 2014/04/20 16:46:04 schwarze Exp $ */
+/* $Id: man_term.c,v 1.147 2014/04/20 20:18:12 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -28,6 +28,7 @@
#include <string.h>
#include "mandoc.h"
+#include "mandoc_aux.h"
#include "out.h"
#include "man.h"
#include "term.h"
@@ -1049,9 +1050,9 @@ print_man_nodelist(DECL_ARGS)
static void
print_man_foot(struct termp *p, const void *arg)
{
- char title[BUFSIZ];
- size_t datelen;
- const struct man_meta *meta;
+ const struct man_meta *meta;
+ char *title;
+ size_t datelen;
meta = (const struct man_meta *)arg;
assert(meta->title);
@@ -1071,11 +1072,12 @@ print_man_foot(struct termp *p, const void *arg)
if ( ! p->mdocstyle) {
term_vspace(p);
term_vspace(p);
- snprintf(title, BUFSIZ, "%s(%s)", meta->title, meta->msec);
+ mandoc_asprintf(&title, "%s(%s)",
+ meta->title, meta->msec);
} else if (meta->source) {
- strlcpy(title, meta->source, BUFSIZ);
+ title = mandoc_strdup(meta->source);
} else {
- title[0] = '\0';
+ title = mandoc_strdup("");
}
datelen = term_strlen(p, meta->date);
@@ -1111,14 +1113,16 @@ print_man_foot(struct termp *p, const void *arg)
term_word(p, title);
term_flushln(p);
+ free(title);
}
static void
print_man_head(struct termp *p, const void *arg)
{
- char buf[BUFSIZ], title[BUFSIZ];
- size_t buflen, titlen;
- const struct man_meta *meta;
+ char buf[BUFSIZ];
+ const struct man_meta *meta;
+ char *title;
+ size_t buflen, titlen;
meta = (const struct man_meta *)arg;
assert(meta->title);
@@ -1132,7 +1136,7 @@ print_man_head(struct termp *p, const void *arg)
/* Top left corner: manual title and section. */
- snprintf(title, BUFSIZ, "%s(%s)", meta->title, meta->msec);
+ mandoc_asprintf(&title, "%s(%s)", meta->title, meta->msec);
titlen = term_strlen(p, title);
p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
@@ -1183,4 +1187,5 @@ print_man_head(struct termp *p, const void *arg)
term_vspace(p);
term_vspace(p);
}
+ free(title);
}