From 478131463a63046a582b3c8d04d5773b4128be7e Mon Sep 17 00:00:00 2001 From: schwarze Date: Sun, 20 Apr 2014 19:39:35 +0000 Subject: [PATCH] make sure static buffers for snprintf(3) are large enough and cast snprintf return value to (void) where they are --- usr.bin/mandoc/eqn.c | 4 ++-- usr.bin/mandoc/mdoc_man.c | 13 +++++++------ usr.bin/mandoc/mdoc_term.c | 6 +++--- usr.bin/mandoc/mdoc_validate.c | 12 +++++------- usr.bin/mandoc/roff.c | 8 ++++---- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/usr.bin/mandoc/eqn.c b/usr.bin/mandoc/eqn.c index 305b629d138..584e2b9dadb 100644 --- a/usr.bin/mandoc/eqn.c +++ b/usr.bin/mandoc/eqn.c @@ -1,4 +1,4 @@ -/* $Id: eqn.c,v 1.7 2014/04/20 16:44:44 schwarze Exp $ */ +/* $Id: eqn.c,v 1.8 2014/04/20 19:39:35 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -624,7 +624,7 @@ eqn_box(struct eqn_node *ep, struct eqn_box *last) for (i = 0; i < (int)EQNSYM__MAX; i++) if (EQNSTREQ(&eqnsyms[i].str, start, sz)) { sym[63] = '\0'; - snprintf(sym, 62, "\\[%s]", eqnsyms[i].sym); + (void)snprintf(sym, 62, "\\[%s]", eqnsyms[i].sym); bp->text = mandoc_strdup(sym); return(EQN_OK); } diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index 979926a5371..813a28a2b6a 100644 --- a/usr.bin/mandoc/mdoc_man.c +++ b/usr.bin/mandoc/mdoc_man.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_man.c,v 1.61 2014/04/20 16:44:44 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.62 2014/04/20 19:39:35 schwarze Exp $ */ /* * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze * @@ -453,7 +453,7 @@ print_offs(const char *v) if (Bl_stack_len) sz += Bl_stack[Bl_stack_len - 1]; - snprintf(buf, sizeof(buf), "%zun", sz); + (void)snprintf(buf, sizeof(buf), "%zun", sz); print_word(buf); outflags |= MMAN_nl; } @@ -506,7 +506,7 @@ print_width(const char *v, const struct mdoc_node *child, size_t defsz) remain = sz + 2; } if (numeric) { - snprintf(buf, sizeof(buf), "%zun", sz + 2); + (void)snprintf(buf, sizeof(buf), "%zun", sz + 2); print_word(buf); } else print_word(v); @@ -516,9 +516,9 @@ print_width(const char *v, const struct mdoc_node *child, size_t defsz) static void print_count(int *count) { - char buf[12]; + char buf[24]; - snprintf(buf, sizeof(buf), "%d.", ++*count); + (void)snprintf(buf, sizeof(buf), "%d.", ++*count); print_word(buf); } @@ -1312,7 +1312,8 @@ mid_it(void) /* Restore the indentation of the enclosing list. */ print_line(".RS", MMAN_Bk_susp); - snprintf(buf, sizeof(buf), "%zun", Bl_stack[Bl_stack_len - 1]); + (void)snprintf(buf, sizeof(buf), "%zun", + Bl_stack[Bl_stack_len - 1]); print_word(buf); /* Remeber to close out this .RS block later. */ diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index 8be99fff9bd..256c599e31c 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.166 2014/04/20 16:44:44 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.167 2014/04/20 19:39:35 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze @@ -616,7 +616,7 @@ static int termp_it_pre(DECL_ARGS) { const struct mdoc_node *bl, *nn; - char buf[7]; + char buf[24]; int i; size_t width, offset, ncols, dcol; enum mdoc_list type; @@ -912,7 +912,7 @@ termp_it_pre(DECL_ARGS) break; case LIST_enum: (pair->ppair->ppair->count)++; - snprintf(buf, sizeof(buf), "%d.", + (void)snprintf(buf, sizeof(buf), "%d.", pair->ppair->ppair->count); term_word(p, buf); break; diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index ec1c12ba317..925a890d87f 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.128 2014/04/20 16:44:44 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.129 2014/04/20 19:39:35 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -41,8 +41,6 @@ #define PRE_ARGS struct mdoc *mdoc, struct mdoc_node *n #define POST_ARGS struct mdoc *mdoc -#define NUMSIZ 32 - enum check_ineq { CHECK_LT, CHECK_GT, @@ -1384,7 +1382,7 @@ post_bl_block_width(POST_ARGS) int i; enum mdoct tok; struct mdoc_node *n; - char buf[NUMSIZ]; + char buf[24]; n = mdoc->last; @@ -1416,7 +1414,7 @@ post_bl_block_width(POST_ARGS) assert(i < (int)n->args->argc); - snprintf(buf, NUMSIZ, "%un", (unsigned int)width); + (void)snprintf(buf, sizeof(buf), "%un", (unsigned int)width); free(n->args->argv[i].value[0]); n->args->argv[i].value[0] = mandoc_strdup(buf); @@ -1431,7 +1429,7 @@ post_bl_block_tag(POST_ARGS) struct mdoc_node *n, *nn; size_t sz, ssz; int i; - char buf[NUMSIZ]; + char buf[24]; /* * Calculate the -width for a `Bl -tag' list if it hasn't been @@ -1466,7 +1464,7 @@ post_bl_block_tag(POST_ARGS) /* Defaults to ten ens. */ - snprintf(buf, NUMSIZ, "%un", (unsigned int)sz); + (void)snprintf(buf, sizeof(buf), "%un", (unsigned int)sz); /* * We have to dynamically add this to the macro's argument list. diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 57ab76b1dc3..0b05d955401 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.80 2014/04/20 16:44:44 schwarze Exp $ */ +/* $Id: roff.c,v 1.81 2014/04/20 19:39:35 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -484,7 +484,7 @@ roff_alloc(struct mparse *parse, int options) static enum rofferr roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos) { - char ubuf[12]; /* buffer to print the number */ + char ubuf[24]; /* buffer to print the number */ const char *start; /* start of the string to process */ const char *stesc; /* start of an escape sequence ('\\') */ const char *stnam; /* start of the name, after "[(*" */ @@ -610,11 +610,11 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos) ubuf[1] = '\0'; break; case 'n': - snprintf(ubuf, sizeof(ubuf), "%d", + (void)snprintf(ubuf, sizeof(ubuf), "%d", roff_getregn(r, stnam, naml)); break; case 'w': - snprintf(ubuf, sizeof(ubuf), "%d", + (void)snprintf(ubuf, sizeof(ubuf), "%d", 24 * (int)naml); break; } -- 2.20.1