source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: When the database is corrupt in the sense of containing invalid
Date: Tue, 30 Aug 2016 17:01:38 -0500 (EST)	[thread overview]
Message-ID: <15930894204161614524.enqueue@fantadrom.bsd.lv> (raw)

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

                 reply	other threads:[~2016-08-30 22:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15930894204161614524.enqueue@fantadrom.bsd.lv \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).