Newsgroups: comp.unix.ultrix Path: utzoo!utgpu!watserv1!watcgl!idallen From: "Ian! D. Allen [CGL]" Subject: Ultrix 4.1 "find" command bug triggers /bin/sh bug Message-ID: <1991May15.185903.17055@watcgl.waterloo.edu> Sender: idallen@watcgl.waterloo.edu (Ian! D. Allen [CGL]) Organization: Computer Graphics Laboratory, University of Waterloo, Ontario, Canada Date: Wed, 15 May 1991 18:59:03 GMT Lines: 86 #!/bin/sh # A script that shows how a bug in FIND triggers a bug in /bin/sh # # This bug exists on: # Ultrix 4.1 RISC, Ultrix 3.1C RISC, Ultrix 3.1 VAX, etc. # Unix 4.3BSD, Sequent DYNIX # It does not exit on: # Irix 3.3.1, RISC/os (UMIPS) 4.51, SunOS 4.x # # The FIND program opens directories as it goes down a tree. # Those descriptors remain open across the -exec of a program. # If that program happens to be /bin/sh, and the depth is right (8), # /bin/sh will silently exit (and not run your shell script). # # This means if you use FIND to search your file system and execute # a Bourne shell script to do something, it won't work on directories # eight deep. # # FIX: # # FIND should use fcntl F_SETFD to set the close-on-exec flag on all # its open directory descriptors. The "-exec" sub-processes should not # inherit them. # # /bin/sh should be more clever about its file descriptors and not # exit silently because the descriptor it wants to use is occupied. # # Work around: # # Change all your FIND commands to -print the file names and use some # other script to read the names and perform the actions you want. # Note that using xargs incorrectly may result in security problems. # (See back issues of comp.unix.shell etc.) # # Submit an SPR. #----------------------------------------------------------------------- # any name will do here name=x7x cd /tmp rm -rf $name # nest some directories for i in 1 2 3 4 5 6 7 ; do mkdir $name && cd $name done # create a file at the bottom echo hi >file # start back at the top cd /tmp # create a /bin/sh script rm -f shscript cat >shscript <shscript <