summaryrefslogtreecommitdiffstats
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
commit0e671b23106993a04ea9629722c1308693db3523 (patch)
tree349486bf660b15ebf9ca04fe31b0617fcfa8bd95 /man_term.c
parent846dd76f5940424c60690661ffd74602f74b5051 (diff)
downloadmandoc-0e671b23106993a04ea9629722c1308693db3523.tar.gz
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.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/man_term.c b/man_term.c
index c17fd96d..57e7fa71 100644
--- a/man_term.c
+++ b/man_term.c
@@ -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);
}