Bug 200580 - superfluous/unnecessary endhostent() does close(0) by accident. libc resolver dns fd close
Summary: superfluous/unnecessary endhostent() does close(0) by accident. libc resolver...
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.1-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-01 21:09 UTC by Juha Nurmela
Modified: 2018-05-21 00:00 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Juha Nurmela 2015-06-01 21:09:26 UTC
Calling endhostent(), when such a call is not needed,
ends up closing fd 0 by accident.

main()
{
        endhostent();
}

Breakpoint 2, 0x281a8dc0 in close () from /lib/libc.so.7
(gdb) where
#0  0x281a8dc0 in close () from /lib/libc.so.7
#1  0x28152518 in __res_nclose () from /lib/libc.so.7
#2  0x2817c585 in __dns_getanswer () from /lib/libc.so.7
#3  0x080485b3 in main () at endhostent_bug.c:4

hopo $ truss ./a.out
...
close(0)                                         = 0 (0x0)
...
process exit, rval = 0

Except the usual runtime chores, close(0) is the only visible systemcall.
Comment 1 Jilles Tjoelker freebsd_committer freebsd_triage 2015-12-28 17:13:30 UTC
I think res_nclose() in lib/libc/resolv/res_init.c should skip its close logic if ((statp->options & RES_INIT) == 0).
Comment 2 Hajimu UMEMOTO freebsd_committer freebsd_triage 2015-12-28 18:47:39 UTC
I don't think it's a bug.
Calling endhostent() alone is rather caller's bug.
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2018-05-21 00:00:16 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"
Comment 4 Eitan Adler freebsd_committer freebsd_triage 2018-05-21 00:00:34 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"