Bug 45744

Summary: /usr/bin/makeinfo sometimes segfaults
Product: Base System Reporter: Ronald F. Guilmette <rfg>
Component: gnuAssignee: ru <ru>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.7-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Ronald F. Guilmette 2002-11-26 09:30:01 UTC
(NOTE:  This bug has also/already been reported to the GNU Project's
maintainer of the GNU texinfo package.)

I have been experiencing segmentation faults in makeinfo for quite a
long time now... over a year.  Please see:

    http://www.freebsd.org/cgi/query-pr.cgi?pr=45598

for more info.

Anyway, I finally got off my ass and tracked down the root cause of
these crashes.

Quite simply, there are cases where the code on line 337 of the makinfo
index.c file, i.e.:

    undefindex (name_index_alist[i]->name);

gets executed when name_index_alist[i] has a NULL value.  And dereferencing
a NULL is a very Bad Idea.  (Doing so causes segfaults.  Oh yea.)

You can tell that the code fully _expects_ that name_index_alist[i] will
have a NULL value, in some cases, at this point in the code, just by looking
at the next following code line, which reads:

    if (name_index_alist[i])

Obviously, it *is* possible for name_index_alist[i] to have a NULL value,
right around this point in the code, and indeed, that condition is even
expected.  The problem is that we are dereferencing that value (on line 337)
before we have checked to see if the value is NULL or not.  (If it is NULL,
then we definitely DO NOT want to perform the deference.)

A suitable (and trivial, and obvious) patch for this error is provided
below.  All that is needed is to move the dereferencing statement to a
point _after_ we have checked if the value of if name_index_alist[i] is
NULL or not.

(The patch below should be suitable for use against both the current
GNU version of the texinfo package, i.e. 4.3, and also the 4.2 version,
as was used in the FreeBSD 4.7-RELEASE distribution.)

How-To-Repeat: 
Please see:

   http://www.freebsd.org/cgi/query-pr.cgi?pr=45598

This bug can be trivially reproduced by simply attempting to build
/usr/ports/devel/autoconf213 and/or /usr/ports/mail/nmh, which it
turn triggers a build of /usr/ports/devel/autoconf213.
Comment 1 Ronald F. Guilmette 2002-11-26 23:57:32 UTC
It would appear that the GNU Project's maintainer of the GNU texinfo
package (which includes the `makeinfo' utility) concurs with my
opinion that `makeinfo' contained a bug that could cause segfaults.

It would also appear that he concurs with the patch for `makeinfo'
that I sent him.

------- Forwarded Message

Return-Path: karl@freefriends.org
Delivery-Date: Tue Nov 26 15:16:30 2002
Return-Path: <karl@freefriends.org>
Delivered-To: rfg@monkeys.com
Received: from f7.net (consort.superb.net [209.61.216.22])
	by segfault.monkeys.com (Postfix) with ESMTP id AB1B24225E
	for <rfg@monkeys.com>; Tue, 26 Nov 2002 15:16:28 -0800 (PST)
Received: (from karl@localhost)
	by f7.net (8.11.6/8.11.6) id gAQNGRb05480;
	Tue, 26 Nov 2002 18:16:27 -0500
Date: Tue, 26 Nov 2002 18:16:27 -0500
Message-Id: <200211262316.gAQNGRb05480@f7.net>
From: karl@freefriends.org (Karl Berry)
To: rfg@monkeys.com
Cc: bug-texinfo@gnu.org
Subject: Re: Segfault in makeinfo in GNU texinfo-4.3 package (fix included)

    I have been experiencing segmentation faults in makeinfo for quite a
    long time now... over a year.  Please see:

        http://www.freebsd.org/cgi/query-pr.cgi?pr=45598

Ah.  Sorry, I wasn't aware of this.

    Obviously, it *is* possible for name_index_alist[i] to have a NULL value,

Indeed.  I moved the undefindex call after the conditional just as you
suggested.

Thanks much for the report and fix!

~karl

------- End of Forwarded Message
Comment 2 Kris Kennaway freebsd_committer freebsd_triage 2003-07-13 01:21:11 UTC
Responsible Changed
From-To: freebsd-bugs->ru

Assign to texinfo maintainer
Comment 3 ru freebsd_committer freebsd_triage 2003-07-19 22:37:56 UTC
State Changed
From-To: open->closed

This has been fixed in GNU texinfo 4.6.