Subject: sharutils-4.2.1/NetBSD-1.4.1 core dumps
To: None <bug-gnu-utils@prep.ai.mit.edu>
From: Makoto Fujiwara <makoto@ki.nu>
List: netbsd-bugs
Date: 11/30/1999 15:36:31
----Next_Part(Tue_Nov_30_15:33:35_1999_542)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

  Thanks for releasing various GNU tools, I am totally happy
with using these tools.
  
  One thing I have noticed that mailshar core dumps. I have 
once thought it is a problem on NetBSD side, but it turned out
it is just a simple problem printing 

struct_stat.st_size with long integer.

I will attach the patch, the original core dump report ( primarily for
netbsd send-pr purpose), and some related comments responded.

(Chris, thanks for resposes, please close the PR lib/8912).
---

----Next_Part(Tue_Nov_30_15:33:35_1999_542)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="shar.c-patch"

--- sharutils-4.2.1/src/shar.c-o	Sat Sep 11 04:20:41 1999
+++ sharutils-4.2.1/src/shar.c	Tue Nov 30 15:11:40 1999
@@ -696,7 +696,7 @@
      const char *local_name;
      const char *restore_name;
 {
-  fprintf (output, "# %6ld %s %s\n", struct_stat.st_size,
+  fprintf (output, "# %6ld %s %s\n", (long) struct_stat.st_size,
 	   mode_string (struct_stat.st_mode), restore_name);
   return 0;
 }

----Next_Part(Tue_Nov_30_15:33:35_1999_542)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="sharutils core dumps"

++++ building sharutils-4.2.1
./configure
time make 

sed -f ../intl/po2msg.sed < ja_JP.EUC.po > ja_JP.EUC.msg  && rm -f ja_JP.EUC.cat && /usr/bin/gencat ja_JP.EUC.cat ja_JP.EUC.msg
gencat: specified msg doesn't exist on line 158
49 
gencat: unrecognized escape sequence on line 351
  -e, --exit-0                `--split-at=\"exit 0\"' \n\
....
making all in checks
making all in contrib
132.611u 12.503s 2:42.23 89.4%  0+0k 115+821io 109pf+0w
makoto@fujiwara  9:17:24/991129(...src/sharutils-4.2.1)> 

+++++ make install
makoto@fujiwara 9:18:50/991129(...src/sharutils-4.2.1)> su
Password:
# make install
for subdir in doc lib po intl src checks contrib; do  target=`echo install|sed 's/-recursive//'`;  echo making $target in $subdir;  (cd $subdir && make $target)  || case " " in *k*) fail=yes;; *) exit 1;; esac;  done && test -z "$fail"
making install in doc
../mkinstalldirs /usr/local/info
cd . &&  for file in sharutils.info* remsync.info*; do  /usr/local/bin/install -c -m 644 $file /usr/local/info/$file;  done
making install in lib
making install in po
../mkinstalldirs /usr/local/lib
catalogs='de.cat de.gmo fr.cat fr.gmo ja_JP.EUC.cat ja_JP.EUC.gmo nl.cat nl.gmo pt.cat pt.gmo sv.cat sv.gmo';  for cat in $catalogs; do  if test "`echo $cat | sed 's/.*\(\..*\)/\1/'`" = ".gmo"; then  destdir=/usr/local/share/locale;  else  destdir=/usr/local/lib/locale;  fi;  lang=`echo $cat | sed 's/.cat$//'`;  dir=$destdir/$lang/LC_MESSAGES;  ../mkinstalldirs $dir;  if test -r $cat; then  /usr/local/bin/install -c -m 644 $cat $dir/sharutils.cat;  else  /usr/local/bin/install -c -m 644 ./$cat $dir/sharutils.cat;  fi;  done
making install in intl
making install in src
../mkinstalldirs /usr/local/bin
for name in shar unshar uudecode uuencode; do  /usr/local/bin/install -c $name  /usr/local/bin/`echo $name | sed 's,x,x,'`;  done;
for name in mailshar mail-files remsync; do  /usr/local/bin/install -c -m 755 $name  /usr/local/bin/`echo $name | sed 's,x,x,'`;  done
making install in checks
making install in contrib
# 

++++  checking the function
makoto@fujiwara  9:20:46/991129(...htdocs/usrlocal)> mailshar makoto@ki.nu gs*
Segmentation fault - core dumped
makoto@fujiwara  9:20:54/991129(...htdocs/usrlocal)> ls -l gs*
-rw-r--r--   1 makoto   10           2078 Nov 28 14:32 gs-Makefile.patch
-rw-r--r--   1 makoto   wheel         245 Nov 26 13:27 gs-gxxfvf.c-patch
-rw-r--r--   1 makoto   wheel         355 Nov 26 15:40 gs-gxxfvf.c-patch-VF_Init
-rw-r--r--   1 makoto   wheel       18262 Nov 28 14:42 gs.shtml

++++  see what happens with gdb
makoto@fujiwara  9:20:54/991129(...htdocs/usrlocal)> ls *core
shar.core
makoto@fujiwara  9:21:13/991129(...htdocs/usrlocal)> gdb /usr/local/bin/shar shar.core
GNU gdb 4.17
Copyright 1998 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 "sparc--netbsd"...
Core was generated by `shar'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/libexec/ld.so...done.
Reading symbols from /usr/lib/libc.so.12.40...done.
#0  0x10085000 in strlen ()
(gdb) where
#0  0x10085000 in strlen ()
#1  0x10082fa4 in vfprintf ()
#2  0x100823c4 in fprintf ()
#3  0x3a9c in generate_one_header_line (local_name=0xeffff280 "gs-Makefile.patch", restore_name=0xeffff280 "gs-Makefile.patch") at shar.c:699
#4  0x2ae8 in walkdown (routine=0x3a68 <generate_one_header_line>, local_name=0xeffff280 "gs-Makefile.patch", restore_name=0xeffff280 "gs-Makefile.patch") at shar.c:287
#5  0x2d50 in walktree (routine=0x3a68 <generate_one_header_line>, local_name=0xeffff61b "gs-Makefile.patch") at shar.c:410
#6  0x44f0 in generate_full_header (argc=4, argv=0xeffff550) at shar.c:856
#7  0x81b0 in main (argc=11, argv=0xeffff534) at shar.c:2082
(gdb) 

-------------------------------------------------------------
/*---.
| ?  |
`---*/

static int
generate_one_header_line (local_name, restore_name)
     const char *local_name;
     const char *restore_name;
{
  fprintf (output, "# %6ld %s %s\n", struct_stat.st_size,
	   mode_string (struct_stat.st_mode), restore_name);
  return 0;
}
-------------- (man fprintf) -------------------------------
     #include <stdarg.h>
     int
     vfprintf(FILE *stream, const char *format, va_list ap);
-------------------------------------------------------------



----Next_Part(Tue_Nov_30_15:33:35_1999_542)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="Mail from Chris"

	by fujiwara.sps.mot.com (8.8.8/3.7W_scg-1.1-990506) with ESMTP id FAA14234
	for <fujiwara@papageno.sps.mot.com>; Tue, 30 Nov 1999 05:43:01 +0900 (JST)
To: "Makoto Fujiwara (rty029)" <makoto.fujiwara@onsemi.com>
Cc: gnats-bugs@gnats.netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: lib/8912: sharutils-4.2, sharutils-4.1 core dumps at vfprintf ()
References: <199911290056.JAA11246@fujiwara.sps.mot.com>
From: cgd@netbsd.org (Chris G. Demetriou)
Date: 29 Nov 1999 12:42:37 -0800
In-Reply-To: makoto@ki.nu's message of Mon, 29 Nov 1999 09:56:29 +0900 (JST)
Message-Id: <87vh6ljagy.fsf@redmail.netbsd.org>
Lines: 31

makoto@ki.nu writes:
> static int
> generate_one_header_line (local_name, restore_name)
>      const char *local_name;
>      const char *restore_name;
> {
>   fprintf (output, "# %6ld %s %s\n", struct_stat.st_size,
> 	   mode_string (struct_stat.st_mode), restore_name);
>   return 0;
> }
> -------------- (man fprintf) -------------------------------
>      #include <stdarg.h>
>      int
>      vfprintf(FILE *stream, const char *format, va_list ap);
> -------------------------------------------------------------

The source code calling fprintf is buggy.

the st_size member of struct stat is an off_t -- the code assumes
that it's a long.  There's no guarantee that the two are the same.

For the code to be correct (or at least, more correct, i'm not looking
for all of the potential bugs in the code 8-), it'd have cast
struct_stat.st_size to (long) before printing it with %ld.



cgd
-- 
Chris Demetriou - cgd@netbsd.org - http://www.netbsd.org/People/Pages/cgd.html
Disclaimer: Not speaking for NetBSD, just expressing my own opinion.

----Next_Part(Tue_Nov_30_15:33:35_1999_542)--
Content-Type: Message/Rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="-Wformat -Werror"

	by fujiwara.sps.mot.com (8.8.8/3.7W_scg-1.1-990506) with ESMTP id FAA14242
	for <fujiwara@papageno.sps.mot.com>; Tue, 30 Nov 1999 05:46:11 +0900 (JST)
From: cgd@netbsd.org
Date: 29 Nov 1999 20:45:49 -0000
Message-Id: <19991129204549.19582.qmail@mail.netbsd.org>
To: "Makoto Fujiwara (rty029)" <makoto.fujiwara@onsemi.com>, cgd@netbsd.org,
        lib-bug-people@netbsd.org, cgd@netbsd.org
Subject: Re: lib/8912

Synopsis: vfprintf/strlen problem (stdargs.h)

State-Changed-From-To: open-feedback
State-Changed-By: cgd
State-Changed-When: Mon Nov 29 12:43:32 PST 1999
State-Changed-Why: 
reply from me incoming.  This is _not_ a bug in the NetBSD
libraries or system, it is a bug in the sharutils source code.
My mail explains the problem.  Please confirm my understanding
of the problem, then reply (being sure to cc gnats-bugs@netbsd.org),
and I will close the PR.  The proper solution for this problem
is to feed a fix back to the sharutils maintainers, to use
-Wformat -Werror when compiling with gcc.  (err, "and to use.")


Responsible-Changed-From-To: lib-bug-people->cgd
Responsible-Changed-By: cgd
Responsible-Changed-When: Mon Nov 29 12:43:32 PST 1999
Responsible-Changed-Why: 
see above.

----Next_Part(Tue_Nov_30_15:33:35_1999_542)----