man dumps core if no manpath.config directories exist
#0 0x0804c7fb in get_manpath (perrs=0, path=0x800 Address 0x800 out of bounds) at /usr/src/gnu/usr.bin/man/manpath/manpath.c:500 #1 0x0804bf30 in manpath (perrs=0) at /usr/src/gnu/usr.bin/man/manpath/manpath.c:195 #2 0x08049a2b in man_getopt (argc=0, argv=0x0) at /usr/src/gnu/usr.bin/man/man/man.c:479 #3 0x080491fe in main (argc=1, argv=0xbfbff78c) at /usr/src/gnu/usr.bin/man/man/man.c:153 #4 0x080490dc in _start (ap=0xbfbff888 man) at /usr/src/lib/csu/i386-elf/crt1.c:126 (gdb) frame 0 #0 0x0804c7fb in get_manpath (perrs=0, path=0x800 Address 0x800 out of bounds) at /usr/src/gnu/usr.bin/man/manpath/manpath.c:500 500 *manpathlist = '\0'; (gdb) print len $1 = 0 It's pretty clear what's going on..none of the directories in /etc/manpath.config exist, so len=0, so malloc(0) succeeds and does nothing, leaving manpathlist a null pointer. This situation can occur if e.g. you install the 'base' freebsd distribution into a jail, without installing any of the manpages. In this situation none of the manpage directories are created either. Kris msg45271/pgp0.pgp Description: PGP signature
[PATCH] Re: man dumps core if no manpath.config directories exist
Kris Kennaway wrote: It's pretty clear what's going on..none of the directories in /etc/manpath.config exist, so len=0, so malloc(0) succeeds and does nothing, leaving manpathlist a null pointer. This situation can occur if e.g. you install the 'base' freebsd distribution into a jail, without installing any of the manpages. In this situation none of the manpage directories are created either. Uh... so fix it? Patch attached. Yes, this returns a strdup() without verifying the allocation; just like the caller will return the result of get_manpath() or strdup(), without verifying the allocation. This is generally bad code, and I'm not going to rewrite it to make all the interfaces reflexive, like they should be, to fix a simple bug. -- Terry Index: manpath.c === RCS file: /cvs/src/gnu/usr.bin/man/manpath/manpath.c,v retrieving revision 1.12 diff -c -r1.12 manpath.c *** manpath.c 13 Feb 2001 16:55:42 - 1.12 --- manpath.c 12 Oct 2002 21:03:09 - *** *** 493,498 --- 493,501 lp++; } + if (!len) + return strdup(); + manpathlist = (char *) malloc (len); if (manpathlist == NULL) gripe_alloc (len, manpathlist);
Re: [PATCH] Re: man dumps core if no manpath.config directories exist
On Sat, Oct 12, 2002 at 06:02:59PM -0700, Terry Lambert wrote: Kris Kennaway wrote: It's pretty clear what's going on..none of the directories in /etc/manpath.config exist, so len=0, so malloc(0) succeeds and does nothing, leaving manpathlist a null pointer. This situation can occur if e.g. you install the 'base' freebsd distribution into a jail, without installing any of the manpages. In this situation none of the manpage directories are created either. Uh... so fix it? That's why I reported it. Patch attached. Thanks. Kris msg45284/pgp0.pgp Description: PGP signature