Bug 61492

Summary: getXXbyYY performs an extra close on nis/nisplu lookups
Product: [Retired] Red Hat Linux Reporter: Issue Tracker <tao>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2CC: dcm, fweimer, nmurray, tao
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-03-21 14:42:48 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Patch from Uli likely to fix this. none

Description Issue Tracker 2002-03-20 17:13:44 UTC
Description of Problem:


        #include <netdb.h>

        int main(int argc, char **argv )
        {
                write(1,"A\n",2);
                getservbyname(argv[1],0);
                write(1,"B\n",2);
                return 0;
        }

If I run this with an undefined service name (such as "quack"), I see glibc
trying to close an fd it shouldn't be:

        close(3)                       = 0
        close(3)                       = 0
        A
        close(3)                       = 0
        close(3)                       = 0        close(3)                       = 0
        close(3)                       = 0
        close(3)                       = 0
        close(3)                       = 0
        close(3)                       = 0
        close(3)                       = 0
        close(4)                       = 0
        close(3)                       = 0
        close(4)                       = -1 EBADF (Bad file descriptor)
        close(3)                       = 0
        B

Note, this also happens if nis/nisplus is used before files for service lookups,
and whether a valid service name is used or not. 

If files are checked first, and the lookup succeeds the excess close does not
happen. 

In a multithreaded application the potential exists for reassignment of the fd
before the second (erroneous) close.

Comment 1 Issue Tracker 2002-03-21 14:42:44 UTC
Created attachment 49404 [details]
Patch from Uli likely to fix this.

Comment 2 Jakub Jelinek 2002-04-05 09:00:49 UTC
Fixed in glibc-2.2.4-24.