tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: fix two crashes in mandocdb
Date: Sun, 13 Nov 2011 01:09:29 +0100	[thread overview]
Message-ID: <20111113000929.GD16229@iris.usta.de> (raw)

Hi,

here are two easy, but important bugfixes for mandocdb(8).

Chunk 1 is required such that mandocdb doesn't die on extremely
long files.  In my /usr/share/man tree, i have a few very large
files - not real manuals, but they get in the way.

The man parser produces several tens of thousands of text nodes
from these files.  When mandocdb.c attempts to parse them, it
abuses recursion to walk a linear list, resulting in O(N)
stack size requirements.  Stacks with several tens of thousands
of frames don't work well, the program consistently segfaulted;
overflowing thew stack, i guess.

With the for loop, time requirements are still O(N), but at
least we get constant stack size.  I guess we should scour
the tree for similar bugs.  This might as well crash massively
oversized man(7) manuals during normal formatting.


Chunk 2 is required to avoid running out of file descriptors
when walking large directory trees.  Otherwise, mandocdb keeps
crashing on me because it hits the system resource limit on
open file descriptors.


Using this, i can now run

  # mandocdb /usr/share/man

on my main development machine.

OK?
  Ingo


--- mandocdb.c.orig
+++ mandocdb.c
@@ -1142,10 +1142,9 @@ pman_node(MAN_ARGS)
 		}
 	}
 
-	if (pman_node(hash, buf, dbuf, n->child))
-		return(1);
-	if (pman_node(hash, buf, dbuf, n->next))
-		return(1);
+	for (n = n->child; n; n = n->next)
+		if (pman_node(hash, buf, dbuf, n))
+			return(1);
 
 	return(0);
 }
@@ -1250,6 +1249,7 @@ ofile_dirbuild(const char *dir, int verb, struct of **of)
 		}
 	}
 
+	closedir(d);
 	return(1);
 }
 
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

             reply	other threads:[~2011-11-13  0:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-13  0:09 Ingo Schwarze [this message]
2011-11-13  0:12 ` Kristaps Dzonsons

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=20111113000929.GD16229@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@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).