Subject: pkg/35537: textproc/wdiff almost always segfaults on Linux
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <cheusov@tut.by>
List: pkgsrc-bugs
Date: 02/01/2007 16:00:00
>Number:         35537
>Category:       pkg
>Synopsis:       textproc/wdiff almost always segfaults on Linux
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 01 16:00:00 +0000 2007
>Originator:     Aleksey Cheusov
>Release:        Linux cheusov 2.4.27-2-686 #1 Wed Aug 17 10:34:09 UTC 2005 i686 GNU/Linux
>Organization:
home
>Environment:
Linux cheusov 2.4.27-2-686 #1 Wed Aug 17 10:34:09 UTC 2005 i686 GNU/Linux

>Description:
textproc/wdiff almost always segfaults on Linux

>How-To-Repeat:

0 ~>/usr/pkg/bin/wdiff /dev/null /dev/null
Segmentation fault (core dumped)
139 ~>gdb /usr/pkg/bin/wdiff core 
GNU gdb 6.3-debian
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or 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.
This GDB was configured as "i386-linux"...(no debugging symbols found)
Using host libthread_db library "/lib/libthread_db.so.1".

Core was generated by `/usr/pkg/bin/wdiff /dev/null /dev/null'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/pkg/lib/libncurses.so.5...done.
Loaded symbols for /usr/pkg/lib/libncurses.so.5
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
#0  0x400d130a in mallopt () from /lib/libc.so.6
(gdb) bt
#0  0x400d130a in mallopt () from /lib/libc.so.6
#1  0x400d00df in free () from /lib/libc.so.6
#2  0x400be7bb in fclose () from /lib/libc.so.6
#3  0x0804a314 in ?? ()
#4  0x0804c6c8 in ?? ()
#5  0xbffff4c4 in ?? ()
#6  0xbffff468 in ?? ()
#7  0x0804ac6d in ?? ()
#8  0x0804c6c8 in ?? ()
#9  0x0804bd63 in _IO_stdin_used ()
#10 0x0804bd33 in _IO_stdin_used ()
#11 0x0804b260 in _IO_stdin_used ()
#12 0x00000000 in ?? ()
#13 0x40017968 in ?? ()
#14 0xbffff468 in ?? ()
#15 0x0804b06b in error ()
Previous frame inner to this frame (corrupt stack?)
(gdb)

>Fix:
This patch is actually applied to wdiff in Debian distribution.
I think the same patch should be applied to pkgsrc too.

Index: distinfo
===================================================================
RCS file: /cvsroot/pkgsrc/textproc/wdiff/distinfo,v
retrieving revision 1.5
diff -u -r1.5 distinfo
--- distinfo    20 Mar 2006 18:09:52 -0000      1.5
+++ distinfo    1 Feb 2007 15:49:29 -0000
@@ -6,4 +6,4 @@
 SHA1 (patch-aa) = ae9ed3d3f993f5ee2ed22599b9ce5ac7b47be0ab
 SHA1 (patch-ab) = 9c969894e3a5ef8f9454c6577e230ca9d1e06a06
 SHA1 (patch-ac) = 97311dd14a9a47688463ba325aec7874f69887a9
-SHA1 (patch-ae) = 8889518350ee790575bf24b02ba5c01e6ee76f9e
+SHA1 (patch-ae) = 0d3a3e138589366578f88045fd9163af7dc52678
Index: patches/patch-ae
===================================================================
RCS file: /cvsroot/pkgsrc/textproc/wdiff/patches/patch-ae,v
retrieving revision 1.1
diff -u -r1.1 patch-ae
--- patches/patch-ae    24 Jan 2003 14:12:04 -0000      1.1
+++ patches/patch-ae    1 Feb 2007 15:49:29 -0000
@@ -1,7 +1,7 @@
 $NetBSD: patch-ae,v 1.1 2003/01/24 14:12:04 itohy Exp $
 
---- wdiff.c.orig       Sun Nov  6 16:57:23 1994
-+++ wdiff.c    Fri Jan 24 22:41:01 2003
+--- wdiff.c.orig       1994-11-06 09:57:23.000000000 +0200
++++ wdiff.c
 @@ -168,6 +168,10 @@
  # define L_tmpnam PATH_MAX
  #endif
@@ -80,7 +80,27 @@
  main (int argc, char *const argv[])
  {
    int option_char;            /* option character */
-@@ -1329,5 +1362,5 @@
+@@ -1304,12 +1337,14 @@
+       reformat_diff_output ();
+       fclose (input_file);
+     }
++  else
++    {
++      /* Clean up.  Beware that input_file and output_file might not exist,
++      if a signal occurred early in the program.  */
+ 
+-  /* Clean up.  Beware that input_file and output_file might not exist,
+-     if a signal occurred early in the program.  */
+-
+-  if (input_file)
+-    complete_input_program ();
++      if (input_file)
++        complete_input_program ();
++    }
+ 
+   if (*left_side->temp_name)
+     unlink (left_side->temp_name);
+@@ -1329,5 +1364,5 @@
        || count_changed_left || count_changed_right)
      exit (EXIT_ANY_DIFFERENCE);