Subject: bin/4738: getNAME dumps core if it finds no valid .SH [...] .SH sequence
To: None <gnats-bugs@gnats.netbsd.org>
From: None <frueauf@ira.uka.de>
List: netbsd-bugs
Date: 12/21/1997 22:40:09
>Number:         4738
>Category:       bin
>Synopsis:       getNAME dumps core if it finds no valid .SH [...] .SH sequence
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 21 13:50:01 1997
>Last-Modified:
>Originator:     Thorsten Frueauf
>Organization:
private
	
>Release:        <NetBSD-current source date> NetBSD 1.3_BETA from 19.12.1997
>Environment:
	
System: NetBSD cyberlap 1.3_BETA NetBSD 1.3_BETA (CYBERLAP) #0: Sat Dec 20 20:27:36 MET 1997 frueauf@cyberlap:/usr/src/sys/arch/i386/compile/CYBERLAP i386


>Description:
	
If getNAME gets a man page which has no valid ".SH [...]<cr> [...]<cr> .SH<cr>" 
sequence, it dumps core.

>How-To-Repeat:
	
Try getNAME with the man page "ps2frag.1" which comes with the teTeX package:

[frueauf@cyberlap]/home/frueauf/tmp/getNAME> ./getNAME ps2frag.1
Bus error (core dumped)

[frueauf@cyberlap]/home/frueauf/tmp/getNAME> gdb getNAME getNAME.core
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.16 (i386-netbsd), Copyright 1996 Free Software Foundation, Inc...
Core was generated by `getNAME'.
Program terminated with signal 10, Bus error.
Reading symbols from /usr/libexec/ld.so...done.
Reading symbols from /usr/lib/libc.so.12.20...done.
#0  0x4004e4fd in strcat ()
(gdb) bt
#0  0x4004e4fd in strcat ()
#1  0xefbfcf34 in ?? ()
#2  0x61726673 in ?? ()
Cannot access memory at address 0x707b6567.

Here is the "ps2frag.1" man page for further testing:

--- schnipp ---
.TH ps2frag 1 "Feb 95" TeXware
.SH IMPORTANT NOTICE
The new PSfrag system no longer requires the ps2frag script; instead, it
handles the processing entirely within TeX/LaTeX and DVIPS. I'm sure you
will agree that never needing to run ps2frag again is a nice convenience!
.P
However, there are two significant differences in the way this new version
of PSfrag works. Please make yourself aware of them:
.P
1) XDvi is no longer able to determine where your PSfrag replacements
should
go, so instead it lines them up in a vertical list to the left of the 
figure. This allows you to confirm that they have been typeset properly, at
least. However, to confirm that PSfrag
.B positions 
your replacements properly, you will have to view the PostScript
version of your file with a viewer like GhostView, or print it out. 
This seems to be the
only disadvantage to the elimination of the pre-processing step.
.P
2) If you embed '\\tex' commands inside your figures, you now need to 
explicitly _tell_ PSfrag to process these commands. To do so, use
\\usepackage[scanall]{psfrag}
instead of
\\usepackage{psfrag}
at the beginning of your LaTeX file.
.P
If you only use '\\tex' commands in a small number of figures, then a 
more efficient might be to turn on '\\tex'-scanning only for those
figures. To do that, add the command '\\psfragscanon' immediately before 
each relevant \\includegraphics or \\epsfbox command.
.P
.SH NOTES
See the PSfrag documentation for further information.
.SH "SEE ALSO"
dvips(1), gs(1), ghostview(1), latex(1)
.SH AUTHORS
.IP psfrag@rascals.stanford.edu
The PSfrag maintainer's mailing list.
--- schnapp ---

>Fix:
	
>From looking at the code it looks like getNAME takes the first ".SH"
and tryes to extract the text until the next ".SH". But if a man page does
not follow this rule (which is arguable a bad man page) it dumps core,
which it should not do IMHO. It should silently exit (although the man page
does not show up in whatis.db - but thats IMHO ok).

The following diff worked for me, apply it to /src/libexec/getNAME/getNAME.c:

*** getNAME.c-orig	Sun Dec 21 22:06:14 1997
--- getNAME.c	Sun Dec 21 22:36:58 1997
***************
*** 158,163 ****
--- 158,164 ----
  				break;
  			if (headbuf[1] == 's' && headbuf[2] == 'h')
  				break;
+ 			exit(0); /* no valid NAME found, exit silently  */
  		}
  		if (i != 0)
  			strcat(linbuf, " ");

>Audit-Trail:
>Unformatted:
getNAME dumps core if it finds no valid .SH [...] .SH sequence