aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandoc.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2019-06-27 15:07:30 +0000
committerIngo Schwarze <schwarze@openbsd.org>2019-06-27 15:07:30 +0000
commitf59a251232e343851a0737c21d9a75ffca28adea (patch)
treeda31a7c00b735bc2d319c8a9b75962f46cf1a55f /mandoc.c
parentb6723d5f5a8ba2f1931221d8b92823fd4654722f (diff)
downloadmandoc-f59a251232e343851a0737c21d9a75ffca28adea.tar.gz
mandoc-f59a251232e343851a0737c21d9a75ffca28adea.tar.zst
mandoc-f59a251232e343851a0737c21d9a75ffca28adea.zip
Fix mandoc_normdate() and the way it is used.
In the past, it could return NULL but the calling code wasn't prepared to handle that. Make sure it always returns an allocated string. While here, simplify the code by handling the "quick" attribute inside mandoc_normdate() rather than at multiple callsites. Triggered by deraadt@ pointing out that snprintf(3) error handling was incomplete in time2a().
Diffstat (limited to 'mandoc.c')
-rw-r--r--mandoc.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/mandoc.c b/mandoc.c
index 564669fe..5a2be88e 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -1,4 +1,4 @@
-/* $Id: mandoc.c,v 1.115 2019/05/21 08:04:21 schwarze Exp $ */
+/* $Id: mandoc.c,v 1.116 2019/06/27 15:07:30 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -494,9 +494,10 @@ time2a(time_t t)
size_t ssz;
int isz;
+ buf = NULL;
tm = localtime(&t);
if (tm == NULL)
- return NULL;
+ goto fail;
/*
* Reserve space:
@@ -520,7 +521,8 @@ time2a(time_t t)
* of looking at LC_TIME.
*/
- if ((isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday)) == -1)
+ isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday);
+ if (isz < 0 || isz > 4)
goto fail;
p += isz;
@@ -530,7 +532,7 @@ time2a(time_t t)
fail:
free(buf);
- return NULL;
+ return mandoc_strdup("");
}
char *
@@ -539,6 +541,9 @@ mandoc_normdate(struct roff_man *man, char *in, int ln, int pos)
char *cp;
time_t t;
+ if (man->quick)
+ return mandoc_strdup(in == NULL ? "" : in);
+
/* No date specified: use today's date. */
if (in == NULL || *in == '\0')