tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* fix two crashes in mandocdb
@ 2011-11-13  0:09 Ingo Schwarze
  2011-11-13  0:12 ` Kristaps Dzonsons
  0 siblings, 1 reply; 2+ messages in thread
From: Ingo Schwarze @ 2011-11-13  0:09 UTC (permalink / raw)
  To: tech

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: fix two crashes in mandocdb
  2011-11-13  0:09 fix two crashes in mandocdb Ingo Schwarze
@ 2011-11-13  0:12 ` Kristaps Dzonsons
  0 siblings, 0 replies; 2+ messages in thread
From: Kristaps Dzonsons @ 2011-11-13  0:12 UTC (permalink / raw)
  To: tech

On 13/11/2011 01:09, Ingo Schwarze wrote:
> 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, great find!  Please check this in.

Thanks again,

Kristaps

--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-11-13  0:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-13  0:09 fix two crashes in mandocdb Ingo Schwarze
2011-11-13  0:12 ` Kristaps Dzonsons

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).