aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/man_validate.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 /man_validate.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 'man_validate.c')
-rw-r--r--man_validate.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/man_validate.c b/man_validate.c
index 7c10ea5f..0aa550bd 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -1,4 +1,4 @@
-/* $Id: man_validate.c,v 1.148 2019/03/13 18:29:18 schwarze Exp $ */
+/* $Id: man_validate.c,v 1.149 2019/06/27 15:07:30 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -185,8 +185,7 @@ check_root(CHKARGS)
man->meta.title = mandoc_strdup("");
man->meta.msec = mandoc_strdup("");
- man->meta.date = man->quick ? mandoc_strdup("") :
- mandoc_normdate(man, NULL, n->line, n->pos);
+ man->meta.date = mandoc_normdate(man, NULL, n->line, n->pos);
}
if (man->meta.os_e &&
@@ -369,8 +368,8 @@ post_TH(CHKARGS)
/* ->TITLE<- MSEC DATE OS VOL */
n = n->child;
- if (n && n->string) {
- for (p = n->string; '\0' != *p; p++) {
+ if (n != NULL && n->string != NULL) {
+ for (p = n->string; *p != '\0'; p++) {
/* Only warn about this once... */
if (isalpha((unsigned char)*p) &&
! isupper((unsigned char)*p)) {
@@ -388,9 +387,9 @@ post_TH(CHKARGS)
/* TITLE ->MSEC<- DATE OS VOL */
- if (n)
+ if (n != NULL)
n = n->next;
- if (n && n->string)
+ if (n != NULL && n->string != NULL)
man->meta.msec = mandoc_strdup(n->string);
else {
man->meta.msec = mandoc_strdup("");
@@ -400,17 +399,16 @@ post_TH(CHKARGS)
/* TITLE MSEC ->DATE<- OS VOL */
- if (n)
+ if (n != NULL)
n = n->next;
- if (n && n->string && '\0' != n->string[0]) {
- man->meta.date = man->quick ?
- mandoc_strdup(n->string) :
- mandoc_normdate(man, n->string, n->line, n->pos);
- } else {
+ if (n != NULL && n->string != NULL && n->string[0] != '\0')
+ man->meta.date = mandoc_normdate(man,
+ n->string, n->line, n->pos);
+ else {
man->meta.date = mandoc_strdup("");
mandoc_msg(MANDOCERR_DATE_MISSING,
- n ? n->line : nb->line,
- n ? n->pos : nb->pos, "TH");
+ n == NULL ? nb->line : n->line,
+ n == NULL ? nb->pos : n->pos, "TH");
}
/* TITLE MSEC DATE ->OS<- VOL */