source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: When the database is corrupt in the sense of containing invalid
@ 2016-08-30 22:01 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2016-08-30 22:01 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mdocml:
        dbm.c

Revision Data
-------------
Index: dbm.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/dbm.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Ldbm.c -Ldbm.c -u -p -r1.3 -r1.4
--- dbm.c
+++ dbm.c
@@ -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 s
 		default:
 			abort();
 		}
-		ip = 0;
+		if (cp == NULL) {
+			iteration = ITER_NONE;
+			match = NULL;
+			cp = NULL;
+			ip = npages;
+		} else
+			ip = 0;
 		return res;
 	}
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-08-30 22:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-30 22:01 mdocml: When the database is corrupt in the sense of containing invalid schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).