From 289fdc1a87fd959053d8bda85d6806aa24b682c7 Mon Sep 17 00:00:00 2001 From: schwarze Date: Wed, 17 Aug 2016 20:46:06 +0000 Subject: [PATCH] When the content of a manual page does not specify a section, the empty string got added to the list of sections, breaking the database format slightly and causing the page to not be considered part of any section, not even if a section could be deduced from the directory or from the file name. Bug found due to the bogus pcredemo(3) "manual" in the pcre-8.38p0 package. --- usr.bin/mandoc/dba.c | 9 +++------ usr.bin/mandoc/dba.h | 5 ++--- usr.bin/mandoc/dba_read.c | 9 ++++----- usr.bin/mandoc/mandocdb.c | 5 +++-- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/usr.bin/mandoc/dba.c b/usr.bin/mandoc/dba.c index f48aab94b5c..019aa87fe0c 100644 --- a/usr.bin/mandoc/dba.c +++ b/usr.bin/mandoc/dba.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dba.c,v 1.4 2016/08/17 18:58:31 schwarze Exp $ */ +/* $OpenBSD: dba.c,v 1.5 2016/08/17 20:46:06 schwarze Exp $ */ /* * Copyright (c) 2016 Ingo Schwarze * @@ -128,18 +128,15 @@ dba_write(const char *fname, struct dba *dba) * Create a new page and append it to the pages table. */ struct dba_array * -dba_page_new(struct dba_array *pages, const char *name, const char *sect, - const char *arch, const char *desc, const char *file, enum form form) +dba_page_new(struct dba_array *pages, const char *arch, + const char *desc, const char *file, enum form form) { struct dba_array *page, *entry; page = dba_array_new(DBP_MAX, 0); entry = dba_array_new(1, DBA_STR | DBA_GROW); - if (name != NULL) - dba_array_add(entry, prepend(name, NAME_FILE & NAME_MASK)); dba_array_add(page, entry); entry = dba_array_new(1, DBA_STR | DBA_GROW); - dba_array_add(entry, (void *)sect); dba_array_add(page, entry); if (arch != NULL && *arch != '\0') { entry = dba_array_new(1, DBA_STR | DBA_GROW); diff --git a/usr.bin/mandoc/dba.h b/usr.bin/mandoc/dba.h index fa613f146bd..77879586b16 100644 --- a/usr.bin/mandoc/dba.h +++ b/usr.bin/mandoc/dba.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dba.h,v 1.1 2016/08/01 10:32:39 schwarze Exp $ */ +/* $OpenBSD: dba.h,v 1.2 2016/08/17 20:46:06 schwarze Exp $ */ /* * Copyright (c) 2016 Ingo Schwarze * @@ -40,8 +40,7 @@ struct dba *dba_read(const char *); int dba_write(const char *, struct dba *); struct dba_array *dba_page_new(struct dba_array *, const char *, - const char *, const char *, const char *, - const char *, enum form); + const char *, const char *, enum form); void dba_page_add(struct dba_array *, int32_t, const char *); void dba_page_alias(struct dba_array *, const char *, uint64_t); diff --git a/usr.bin/mandoc/dba_read.c b/usr.bin/mandoc/dba_read.c index cd4db383112..3ab4a397aa8 100644 --- a/usr.bin/mandoc/dba_read.c +++ b/usr.bin/mandoc/dba_read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dba_read.c,v 1.3 2016/08/17 18:58:31 schwarze Exp $ */ +/* $OpenBSD: dba_read.c,v 1.4 2016/08/17 20:46:06 schwarze Exp $ */ /* * Copyright (c) 2016 Ingo Schwarze * @@ -48,12 +48,11 @@ dba_read(const char *fname) dba = dba_new(npages < 128 ? 128 : npages); for (ip = 0; ip < npages; ip++) { pdata = dbm_page_get(ip); - page = dba_page_new(dba->pages, NULL, pdata->sect, - pdata->arch, pdata->desc, pdata->file + 1, *pdata->file); + page = dba_page_new(dba->pages, pdata->arch, + pdata->desc, pdata->file + 1, *pdata->file); for (cp = pdata->name; *cp != '\0'; cp = strchr(cp, '\0') + 1) dba_page_add(page, DBP_NAME, cp); - cp = pdata->sect; - while (*(cp = strchr(cp, '\0') + 1) != '\0') + for (cp = pdata->sect; *cp != '\0'; cp = strchr(cp, '\0') + 1) dba_page_add(page, DBP_SECT, cp); if ((cp = pdata->arch) != NULL) while (*(cp = strchr(cp, '\0') + 1) != '\0') diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c index 1d7565b011c..1e8274b3ed5 100644 --- a/usr.bin/mandoc/mandocdb.c +++ b/usr.bin/mandoc/mandocdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandocdb.c,v 1.175 2016/08/05 17:20:30 schwarze Exp $ */ +/* $OpenBSD: mandocdb.c,v 1.176 2016/08/17 20:46:06 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2016 Ingo Schwarze @@ -1982,11 +1982,12 @@ dbadd(struct dba *dba, struct mpage *mpage) cp = mpage->desc; i = strlen(cp); mustfree = render_string(&cp, &i); - mpage->dba = dba_page_new(dba->pages, mlink->name, mpage->sec, + mpage->dba = dba_page_new(dba->pages, *mpage->arch == '\0' ? mlink->arch : mpage->arch, cp, mlink->file, mpage->form); if (mustfree) free(cp); + dba_page_add(mpage->dba, DBP_SECT, mpage->sec); while (mlink != NULL) { dbadd_mlink(mlink); -- 2.20.1