Subject: bug#70411: [bug] install(1) fails to read /dev/stdin on Darwin

From: Alejandro Colomar <[email-masked]>
Date: Fri, 19 Apr 2024 00:04:19 +0200

Hi Sergei,

On Thu, Apr 18, 2024 at 10:52:32PM +0100, Sergei Trofimovich wrote:
> > The system I have locally is this one:
> > 
> >     $ uname -a
> >     Darwin tests-iMac.local 18.7.0 Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64 x86_64
> 
> I debugged it a bit more locally and it looks like it's a known
> limitation of fstat()/stat() mismatch on FIFOs on Darwin. Example
> program:

Thanks!

> $ cat simple.c
> #include <sys/stat.h>
> #include <assert.h>
> #include <sys/fcntl.h>
> #include <unistd.h>
> #include <stdio.h>
> 
> int main() {
>       struct stat s;
>       int fd;
>       int r;
> 
>       fd = open("/dev/fd/0", O_RDONLY);
>       assert(fd > 0);
>       r = fstat(fd, &s);
>       assert(r == 0);
>       fprintf(stderr, "1: ino=%llu\n", s.st_ino);
>       close(fd);
> 
>       fd = open("/dev/fd/0", O_RDONLY);
>       assert(fd > 0);
>       r = fstat(fd, &s);
>       assert(r == 0);
>       fprintf(stderr, "2: ino=%llu\n", s.st_ino);
>       close(fd);
> 
>       r = stat("/dev/fd/0", &s);
>       assert(r == 0);
>       fprintf(stderr, "3: ino=%llu\n", s.st_ino);
>       close(fd);
> }
> 
> Running:
> 
> $ clang simple.c -o simple && echo 42 | ./simple
> 1: ino=3009428657538693161
> 2: ino=3009428657538693161
> 3: ino=1568241705
> 
> Note how stat() and fstat() don't agree on inode.
> 
> Apparently it's documented in
> https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fstat.2.html
> as
> 
>   BUGS
>      Applying fstat to a socket (and thus to a pipe) returns a zero'd buffer,
>      except for the blocksize field, and a unique device and inode number.
> 
> Perhaps coreutils should avoid inode checks on FIFOs and sockets. They
> are already volatile by nature.

I disagree.  I think coreutils should not try to work on broken systems;
especially when the checks are done for security reasons.  Let the
system die.

Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es/>