Subject: Re: lib/8912: sharutils-4.2, sharutils-4.1 core dumps at vfprintf ()
To: None <makoto.fujiwara@Onsemi.com>
From: Chris G. Demetriou <cgd@netbsd.org>
List: netbsd-bugs
Date: 11/29/1999 12:42:37
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.