bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives


From: Radek Brich
Subject: Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives
Date: Wed, 12 Dec 2007 14:01:18 +0100
User-agent: KMail/1.9.6 (enterprise 0.20071012.724442)

On Wed 12. of December 2007 13:53:20 Radek Brich wrote:
> On Wed 12. of December 2007 12:08:43 Jim Meyering wrote:
> > Radek Brich <address@hidden> wrote:
> > > On Tue 11. of December 2007 13:55:53 you wrote:
> > >> Radek Brich <address@hidden> ha escrit:
> > >> > Although it'd need some cleaning, I'd like to hear what
> > >> > you think about the idea?
> > >>
> > >> Generally speaking, looks nice, except that fstat may fail (e.g. if
> > >> stdout is closed) in which case st_stdout would contain garbage.
> >
> > ...
> >
> > > +  struct stat st_buf;
> > > +  ino_t stdout_ino = fstat(STDOUT_FILENO, &st_buf) == -1 ?
> > > +                     0 : st_buf.st_ino;
> > > +  ino_t archive_ino = stat(archive_name_array[0], &st_buf) == -1 ?
> > > +                     0 : st_buf.st_ino;
> > > +  bool archive_is_stdout = (archive_ino != 0 && archive_ino ==
> > > stdout_ino);
> >
> > You'll want to compare st_dev, as well.
> > Otherwise, there's a small risk of a false positive with
> > a file on a different partition, but with the same inode number.
> >
> > You can use the SAME_INODE macro from gnulib's lib/same-inode.h,
> > since tar already has that file.
>
> Yes, thanks, you are right.
>
> I also tried to make it look less alien in the rest of the code.

Oh, and the 'archive_is_stdout' variable can now be avoided as it'll never be 
tested more than once...

-- 
           Radek Brich
   /__\    Base OS/core services
 ~~~~~~~~  Red Hat, Brno, Czech Rep.

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]