GNU bug report logs - #35713
/dev/stdin problem in cp on Solaris

Previous Next

Package: coreutils;

Reported by: jakub.kulik <at> oracle.com

Date: Mon, 13 May 2019 14:21:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 35713 in the body.
You can then email your comments to 35713 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#35713; Package coreutils. (Mon, 13 May 2019 14:21:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to jakub.kulik <at> oracle.com:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 13 May 2019 14:21:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: jakub.kulik <at> oracle.com
To: bug-coreutils <at> gnu.org
Subject: /dev/stdin problem in cp on Solaris
Date: Mon, 13 May 2019 12:24:17 +0200
[Message part 1 (text/plain, inline)]
Hi,

We found out that the following simple command fails on Solaris with:

 cat srcfile.txt | /usr/gnu/bin/cp /dev/stdin dstfile.txt
 cp: skipping file '/dev/stdin', as it was replaced while being copied

I found that problem is with SAME_INODE macro. It accepts two 
structures, one from stat and another from fstat function. On Solaris, 
each of these can return a different thing. While stat returns 
information about the /dev/fd/0 file itself (linked by /dev/stdin), 
fstat knows much more from the file descriptor and returns info about 
the pipe that is being used. That results in SAME_INODE failing.

This happens in both Coreutils 8.30 and 8.31 (both intel and sparc) but 
it looks like it was seen first in 8.16.

The easiest fix to this issue I came up with is to disable SAME_INODE 
validation for special devices and pipes (as they won't be moved 
anyway). Patch is attached as well as small program that can show stat 
and fstat differences on Solaris.

Thanks
Jakub

[copy.c.patch (text/x-patch, attachment)]
[stdin_test.c (text/x-csrc, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#35713; Package coreutils. (Sun, 26 May 2019 12:26:02 GMT) Full text and rfc822 format available.

Message #8 received at 35713 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: jakub.kulik <at> oracle.com, 35713 <at> debbugs.gnu.org
Subject: Re: bug#35713: /dev/stdin problem in cp on Solaris
Date: Sun, 26 May 2019 13:25:21 +0100
On 13/05/19 11:24, jakub.kulik <at> oracle.com wrote:
> Hi,
> 
> We found out that the following simple command fails on Solaris with:
> 
>   cat srcfile.txt | /usr/gnu/bin/cp /dev/stdin dstfile.txt
>   cp: skipping file '/dev/stdin', as it was replaced while being copied
> 
> I found that problem is with SAME_INODE macro. It accepts two 
> structures, one from stat and another from fstat function. On Solaris, 
> each of these can return a different thing. While stat returns 
> information about the /dev/fd/0 file itself (linked by /dev/stdin), 
> fstat knows much more from the file descriptor and returns info about 
> the pipe that is being used. That results in SAME_INODE failing.
> 
> This happens in both Coreutils 8.30 and 8.31 (both intel and sparc) but 
> it looks like it was seen first in 8.16.
> 
> The easiest fix to this issue I came up with is to disable SAME_INODE 
> validation for special devices and pipes (as they won't be moved 
> anyway)

But what if a file is replaced with a character special device for example?
How about doing something like the following before the SAME_INODE check?

#if _solaris
if (S_IFMT(source_desc) != S_IFMT(src_open_sb)
  stat(src_name, &src_open_sb);
#endif

cheers,
Pádraig




Information forwarded to bug-coreutils <at> gnu.org:
bug#35713; Package coreutils. (Mon, 27 May 2019 14:32:03 GMT) Full text and rfc822 format available.

Message #11 received at 35713 <at> debbugs.gnu.org (full text, mbox):

From: jakub.kulik <at> oracle.com
To: Pádraig Brady <P <at> draigBrady.com>, 35713 <at> debbugs.gnu.org
Subject: Re: bug#35713: /dev/stdin problem in cp on Solaris
Date: Mon, 27 May 2019 12:59:58 +0200
Well, I guess that while improbable, that can happen. I am only thinking 
whether is it possible that both stat and fstat return different devices 
with same S_IFMT but I am not sure about that.

Anyway I tried it with your suggestion and for my use case it works as well.

regards,
Jakub

On 5/26/19 2:25 PM, Pádraig Brady wrote:
> On 13/05/19 11:24, jakub.kulik <at> oracle.com wrote:
>> Hi,
>>
>> We found out that the following simple command fails on Solaris with:
>>
>>    cat srcfile.txt | /usr/gnu/bin/cp /dev/stdin dstfile.txt
>>    cp: skipping file '/dev/stdin', as it was replaced while being copied
>>
>> I found that problem is with SAME_INODE macro. It accepts two
>> structures, one from stat and another from fstat function. On Solaris,
>> each of these can return a different thing. While stat returns
>> information about the /dev/fd/0 file itself (linked by /dev/stdin),
>> fstat knows much more from the file descriptor and returns info about
>> the pipe that is being used. That results in SAME_INODE failing.
>>
>> This happens in both Coreutils 8.30 and 8.31 (both intel and sparc) but
>> it looks like it was seen first in 8.16.
>>
>> The easiest fix to this issue I came up with is to disable SAME_INODE
>> validation for special devices and pipes (as they won't be moved
>> anyway)
> But what if a file is replaced with a character special device for example?
> How about doing something like the following before the SAME_INODE check?
>
> #if _solaris
> if (S_IFMT(source_desc) != S_IFMT(src_open_sb)
>    stat(src_name, &src_open_sb);
> #endif
>
> cheers,
> Pádraig




Information forwarded to bug-coreutils <at> gnu.org:
bug#35713; Package coreutils. (Tue, 28 May 2019 14:38:02 GMT) Full text and rfc822 format available.

Message #14 received at 35713 <at> debbugs.gnu.org (full text, mbox):

From: jakub.kulik <at> oracle.com
To: Pádraig Brady <P <at> draigBrady.com>, 35713 <at> debbugs.gnu.org
Subject: Re: bug#35713: /dev/stdin problem in cp on Solaris
Date: Tue, 28 May 2019 16:37:19 +0200
[Message part 1 (text/plain, inline)]
Hi,

I found a problem with your solution (even though maybe even more 
improbable). If I call it like this: *cp /dev/stdin b.txt < somedevice*, 
both stdin and the argument have the same type and copy still fails.

Possible solution might be to call stat when SAME_INODE fails and try it 
again (regular files and folders can be excluded).

Jakub

On 5/27/19 12:59 PM, jakub.kulik <at> oracle.com wrote:
> Well, I guess that while improbable, that can happen. I am only 
> thinking whether is it possible that both stat and fstat return 
> different devices with same S_IFMT but I am not sure about that.
>
> Anyway I tried it with your suggestion and for my use case it works as 
> well.
>
> regards,
> Jakub
>
> On 5/26/19 2:25 PM, Pádraig Brady wrote:
>> On 13/05/19 11:24, jakub.kulik <at> oracle.com wrote:
>>> Hi,
>>>
>>> We found out that the following simple command fails on Solaris with:
>>>
>>>    cat srcfile.txt | /usr/gnu/bin/cp /dev/stdin dstfile.txt
>>>    cp: skipping file '/dev/stdin', as it was replaced while being 
>>> copied
>>>
>>> I found that problem is with SAME_INODE macro. It accepts two
>>> structures, one from stat and another from fstat function. On Solaris,
>>> each of these can return a different thing. While stat returns
>>> information about the /dev/fd/0 file itself (linked by /dev/stdin),
>>> fstat knows much more from the file descriptor and returns info about
>>> the pipe that is being used. That results in SAME_INODE failing.
>>>
>>> This happens in both Coreutils 8.30 and 8.31 (both intel and sparc) but
>>> it looks like it was seen first in 8.16.
>>>
>>> The easiest fix to this issue I came up with is to disable SAME_INODE
>>> validation for special devices and pipes (as they won't be moved
>>> anyway)
>> But what if a file is replaced with a character special device for 
>> example?
>> How about doing something like the following before the SAME_INODE 
>> check?
>>
>> #if _solaris
>> if (S_IFMT(source_desc) != S_IFMT(src_open_sb)
>>    stat(src_name, &src_open_sb);
>> #endif
>>
>> cheers,
>> Pádraig
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#35713; Package coreutils. (Tue, 28 May 2019 20:47:02 GMT) Full text and rfc822 format available.

Message #17 received at 35713 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: jakub.kulik <at> oracle.com
Cc: 35713 <at> debbugs.gnu.org, Pádraig Brady <P <at> draigBrady.com>
Subject: Re: bug#35713: /dev/stdin problem in cp on Solaris
Date: Tue, 28 May 2019 13:46:08 -0700
[Message part 1 (text/plain, inline)]
Thanks for reporting the problem. Please try the attached patch, which 
I've installed in the development repository.


[0001-cp-fix-dev-stdin-problem-on-Solaris.patch (text/x-patch, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#35713; Package coreutils. (Wed, 29 May 2019 08:52:02 GMT) Full text and rfc822 format available.

Message #20 received at 35713 <at> debbugs.gnu.org (full text, mbox):

From: jakub.kulik <at> oracle.com
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 35713 <at> debbugs.gnu.org, Pádraig Brady <P <at> draigBrady.com>
Subject: Re: bug#35713: /dev/stdin problem in cp on Solaris
Date: Wed, 29 May 2019 10:51:14 +0200
Hi,

thanks for the patch - I tested it and all seems to work with both pipe 
and <<, coreutils test suite is also happy.

Just a small correction on my part, somebody found this bug first at 
8.16, but this might have been there for longer.

thanks
Jakub

On 5/28/19 10:46 PM, Paul Eggert wrote:
> Thanks for reporting the problem. Please try the attached patch, which 
> I've installed in the development repository.
>
>




Information forwarded to bug-coreutils <at> gnu.org:
bug#35713; Package coreutils. (Wed, 29 May 2019 23:47:01 GMT) Full text and rfc822 format available.

Message #23 received at 35713 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: jakub.kulik <at> oracle.com
Cc: 35713 <at> debbugs.gnu.org, Pádraig Brady <P <at> draigBrady.com>
Subject: Re: bug#35713: /dev/stdin problem in cp on Solaris
Date: Wed, 29 May 2019 16:46:22 -0700
[Message part 1 (text/plain, inline)]
On 5/29/19 1:51 AM, jakub.kulik <at> oracle.com wrote:
> somebody found this bug first at 8.16, but this might have been there 
> for longer. 

I looked into the revision history and it seems to have been introduced 
long ago. I installed the attached further patch.


[0001-maint-fix-version-number-in-NEWS.patch (text/x-patch, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#35713; Package coreutils. (Thu, 30 May 2019 13:42:02 GMT) Full text and rfc822 format available.

Message #26 received at 35713 <at> debbugs.gnu.org (full text, mbox):

From: jakub.kulik <at> oracle.com
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 35713 <at> debbugs.gnu.org, Pádraig Brady <P <at> draigBrady.com>
Subject: Re: bug#35713: /dev/stdin problem in cp on Solaris
Date: Thu, 30 May 2019 15:41:48 +0200
Thanks,

I tested the patch on both intel and sparc platform and all seems to 
work without any problem.

So I guess this can be closed as solved.

best regards,
Jakub

On 5/30/19 1:46 AM, Paul Eggert wrote:
> On 5/29/19 1:51 AM, jakub.kulik <at> oracle.com wrote:
>> somebody found this bug first at 8.16, but this might have been there 
>> for longer. 
>
> I looked into the revision history and it seems to have been 
> introduced long ago. I installed the attached further patch.
>
>




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Sun, 02 Jun 2019 06:01:01 GMT) Full text and rfc822 format available.

Notification sent to jakub.kulik <at> oracle.com:
bug acknowledged by developer. (Sun, 02 Jun 2019 06:01:02 GMT) Full text and rfc822 format available.

Message #31 received at 35713-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: jakub.kulik <at> oracle.com
Cc: 35713-done <at> debbugs.gnu.org,
 Pádraig Brady <P <at> draigBrady.com>
Subject: Re: bug#35713: /dev/stdin problem in cp on Solaris
Date: Sat, 1 Jun 2019 23:00:46 -0700
jakub.kulik <at> oracle.com wrote:

> I tested the patch on both intel and sparc platform and all seems to work 
> without any problem.
> 
> So I guess this can be closed as solved.

Thanks for checking; closing.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 30 Jun 2019 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 302 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.