aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dbm.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-08-30 22:01:07 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-08-30 22:01:07 +0000
commit1ae9865424c72b96138d9275a0607da6a1cca536 (patch)
tree2394630509c42d91c8534fd3bc0a5c1881c6eb49 /dbm.c
parente4c83815ad1c33d67a9d2078e7eebbbeeb00dd15 (diff)
downloadmandoc-1ae9865424c72b96138d9275a0607da6a1cca536.tar.gz
mandoc-1ae9865424c72b96138d9275a0607da6a1cca536.tar.zst
mandoc-1ae9865424c72b96138d9275a0607da6a1cca536.zip
When the database is corrupt in the sense of containing invalid
pointers in the pages table, do not access NULL pointers, but gracefully handle the errors. Similar patches will be needed for the macro tables, too. <attila at stalphonsos dot com> audited the code and pointed out to me that dbm_get() can return NULL for corrupted databases, but that isn't handled properly at various places.
Diffstat (limited to 'dbm.c')
-rw-r--r--dbm.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/dbm.c b/dbm.c
index 0c0a8b18..0800f765 100644
--- a/dbm.c
+++ b/dbm.c
@@ -1,4 +1,4 @@
-/* $Id: dbm.c,v 1.3 2016/08/05 23:15:08 schwarze Exp $ */
+/* $Id: dbm.c,v 1.4 2016/08/30 22:01:07 schwarze Exp $ */
/*
* Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -150,10 +150,18 @@ dbm_page_get(int32_t ip)
assert(ip >= 0);
assert(ip < npages);
res.name = dbm_get(pages[ip].name);
+ if (res.name == NULL)
+ res.name = "(NULL)";
res.sect = dbm_get(pages[ip].sect);
+ if (res.sect == NULL)
+ res.sect = "(NULL)";
res.arch = pages[ip].arch ? dbm_get(pages[ip].arch) : NULL;
res.desc = dbm_get(pages[ip].desc);
+ if (res.desc == NULL)
+ res.desc = "(NULL)";
res.file = dbm_get(pages[ip].file);
+ if (res.file == NULL)
+ res.file = " (NULL)";
res.addr = dbm_addr(pages + ip);
return &res;
}
@@ -250,7 +258,13 @@ page_bytitle(enum iter arg_iter, const struct dbm_match *arg_match)
default:
abort();
}
- ip = 0;
+ if (cp == NULL) {
+ iteration = ITER_NONE;
+ match = NULL;
+ cp = NULL;
+ ip = npages;
+ } else
+ ip = 0;
return res;
}