Commit Graph

54 Commits

Author SHA1 Message Date
Don Lewis
d7f12eacbb Don't leak addrinfo if ai->ai_addrlen <= minsiz test fails.
If the ai->ai_addrlen <= minsiz test fails, then freeaddrinfo()
does not get called to free the memory just allocated by getaddrinfo().
Fix by moving ai->ai_addrlen <= minsiz to a separate nested if
block, and keep freeaddrinfo() in the outer block so that freeaddrinfo()
will be called whenever getaddrinfo() succeeds.

Reported by:	Coverity
CID:		1273652
Reviewed by:	ume
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D6756
2016-06-08 09:40:06 +00:00
Don Lewis
0ee6da55a6 Since rdata is only used as an argument to the immediately following
call to res_nopt_rdata(), revert r299879 and fix CID 603941 by moving
	rdata = &buf[n];
inside the if block.

Reported by:	Coverity
CID:		603941
2016-05-16 01:38:24 +00:00
Don Lewis
0abffcb5f8 Likely a false positive ... but make sure that -1 can't be used as an
array index by splitting up a test.

Reported by:	Coverity
CID:		603941
MFC after:	1 week
2016-05-16 01:30:32 +00:00
Pedro F. Giffuni
32223c1b7d libc: spelling fixes.
Mostly on comments.
2016-04-30 01:24:24 +00:00
Andriy Voskoboinyk
2cf5e9365d libc: do not include <sys/types.h> where <sys/param.h> was already included
According to style(9):
> normally, include <sys/types.h> OR <sys/param.h>, but not both.
(<sys/param.h> already includes <sys/types.h> when LOCORE is not defined).
2016-04-18 21:05:15 +00:00
Pedro F. Giffuni
bf51882a09 libc: make some more use of the nitems() macro.
We have an nitems() macro in the <sys/param.h> header that is
convenient to re-use as it makes things easier to read.
Given that it is available already without adding additional
headers and other parts of libc already use it, extend a bit
more its use.
2016-04-16 17:52:00 +00:00
Pedro F. Giffuni
513004a23d libc: replace 0 with NULL for pointers.
While here also cleanup some surrounding code; particularly
drop some malloc() casts.

Found with devel/coccinelle.

Reviewed by:	bde (previous version - all new bugs are mine)
2016-04-10 19:33:58 +00:00
Enji Cooper
8a615d0fa8 Allow users override DEBUG on the command line via DEBUG_FLAGS="-DDEBUG" with
lib/libc/resolv by conditionalizing its definition

MFC after: 3 days
Reviewed by: ume, vangyzen
Differential Revision: https://reviews.freebsd.org/D4519
2015-12-15 05:37:09 +00:00
Eric van Gyzen
c70540ec67 resolver: preserve binary compatibility; reduce header pollution
In r289315, I added new fields to res_state.  This broke binary
backward compatibility.  It also broke some ports (and possibly
other code) by requiring the definition of time_t and struct timespec.

Fix these problems by moving the new fields into __res_state_ext.

Suggested by:	ume
Reviewed by:	ume
MFC after:	3 days
Sponsored by:	Dell Inc.
Differential Revision:	https://reviews.freebsd.org/D4472
2015-12-14 17:21:06 +00:00
Eric van Gyzen
4cf0f1f5b3 resolver: abuse _res a little less
In the past, _res was a global variable.  Now, it's multiple function calls.
Several functions in the resolver use _res multiple times and therefore
call the function(s) far more than necessary.

Fix those callers to store the result of _res in a local variable.

Add __noinline to the definition of res_init() to avoid the code bloat
that these changes would have otherwise incurred.  Thanks to jilles
for noticing this.

Reviewed by:	jilles
MFC after:	1 week
Sponsored by:	Dell Inc.
Differential Revision:	https://reviews.freebsd.org/D3887
2015-10-23 15:56:17 +00:00
Eric van Gyzen
60b27ebb25 resolver: automatically reload /etc/resolv.conf
On each resolver query, use stat(2) to see if the modification time
of /etc/resolv.conf has changed.  If so, reload the file and reinitialize
the resolver library.  However, only call stat(2) if at least two seconds
have passed since the last call to stat(2), since calling it on every
query could kill performance.

This new behavior is enabled by default.  Add a "reload-period" option
to disable it or change the period of the test.

Document this behavior and option in resolv.conf(5).

Polish the man page just enough to appease igor.

https://lists.freebsd.org/pipermail/freebsd-arch/2015-October/017342.html

Reviewed by:	kp, wblock
Discussed with:	jilles, imp, alfred
MFC after:	1 month
Relnotes:	yes
Sponsored by:	Dell Inc.
Differential Revision:	https://reviews.freebsd.org/D3867
2015-10-14 14:26:44 +00:00
Craig Rodrigues
c6a7de08f1 Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-22 15:57:26 +00:00
Craig Rodrigues
25462e6589 Add declarations to eliminate -Wmissing-prototypes warnings 2015-09-20 04:26:55 +00:00
Hajimu UMEMOTO
0df21fef2d Add support for '_' occurring at the beginning or end of a name
component.

PR:		176093
Submitted by:	landonf__at__bikemonkey.org
MFC after:	1 week
2015-06-10 16:15:22 +00:00
Hajimu UMEMOTO
e45764721a Update our stub resolver to final version of libbind.
Obtained from:	ISC
2014-08-12 12:36:06 +00:00
Hajimu UMEMOTO
08d41c70c1 We don't use these files. 2014-08-10 15:21:26 +00:00
Pedro F. Giffuni
046c3635cd Bring final version of libbind:
From
http://www.isc.org/downloads/libbind/

The libbind functions have been separated from the BIND suite as of BIND
9.6.0. Originally from older versions of BIND, they have been continually
maintained and improved but not installed by default with BIND 9. This
standard resolver library contains the same historical functions and
headers included with many Unix operating systems. In fact, most
implementations are based on the same original code.

At present, NetBSD maintains libbind code, now known as "netresolv".
2014-08-05 23:16:31 +00:00
Marcel Moolenaar
8876613dc5 Replace use of ${.CURDIR} by ${LIBC_SRCTOP} and define ${LIBC_SRCTOP}
if not already defined. This allows building libc from outside of
lib/libc using a reach-over makefile.

A typical use-case is to build a standard ILP32 version and a COMPAT32
version in a single iteration by building the COMPAT32 version using a
reach-over makefile.

Obtained from:	Juniper Networks, Inc.
2014-03-04 02:19:39 +00:00
Jilles Tjoelker
e852d6bc48 libc/resolv: Use poll() instead of kqueue().
The resolver in libc creates a kqueue for watching a single file descriptor.
This can be done using poll() which should be lighter on the kernel and
reduce possible problems with rlimits (file descriptors, kqueues).

Reviewed by:	jhb
2014-01-14 22:05:33 +00:00
Jilles Tjoelker
d4c612c3b8 libc: Make resolver sockets close-on-exec (SOCK_CLOEXEC).
Although the resolver's sockets are exposed to applications via res_state,
I do not expect them to pass the sockets across execve().
2013-09-06 23:49:54 +00:00
Jilles Tjoelker
a93705b06e libc: Make various internal file descriptors from fopen() close-on-exec. 2013-08-23 13:59:47 +00:00
Dimitry Andric
477433d829 Remove meaningless self-assignment in res_send.c, otherwise clang will
warn about it.  I guess this was originally done to silence a bogus
warning by an older version of gcc, but I could not reproduce it with
any version of gcc that I have access to.

MFC after:	1 week
2011-12-15 20:10:12 +00:00
Xin LI
a28076c8f7 Add an option to enforce strict RFC 1034 compliance.
PR:		kern/129477
2009-05-29 07:34:54 +00:00
Hajimu UMEMOTO
54ebdd631d Merge the resolver part of BIND 9.4.3 into HEAD.
It includes the following fix:

  2426.   [bug]           libbind: inet_net_pton() can sometimes return the
                          wrong value if excessively large netmasks are
                          supplied. [RT #18512]

Reported by:	Maksymilian Arciemowicz <cxib__at__securityreason.com>
2008-12-14 19:39:53 +00:00
Hajimu UMEMOTO
9aeb4147cc Import the resolver part of BIND 9.4.3. 2008-12-14 16:47:21 +00:00
Xin LI
5435230b4d Allow underscore in domain names while resolving. While having underscore
is a violation of RFC 1034 [STD 13], it is accepted by certain name servers
as well as other popular operating systems' resolver library.

Bugs are mine.

Obtained from:	ume
MFC after:	2 weeks
2008-02-16 00:16:49 +00:00
Hajimu UMEMOTO
d069c2b7f5 Merge BIND 9.4.2 into main chunk. 2007-12-03 15:13:44 +00:00
Hajimu UMEMOTO
4117715965 Vendor import of BIND 9.4.2 2007-12-03 15:07:58 +00:00
Hajimu UMEMOTO
dde4a85d9d Merge BIND 9.4.1 into main chunk.
MFC after:	2 weeks
2007-06-03 17:20:27 +00:00
Hajimu UMEMOTO
861249f583 Vendor import of BIND 9.4.1 2007-06-03 17:02:29 +00:00
Hajimu UMEMOTO
46cf4f0985 This commit was generated by cvs2svn to compensate for changes in r170242,
which included commits to RCS files with non-trunk default branches.
2007-06-03 17:02:29 +00:00
Daniel Eischen
5f864214bb Use C comments since we now preprocess these files with CPP. 2007-04-29 14:05:22 +00:00
Alexander Kabaev
84830e00cf __p_rcode_syms is declared as external in resolv.conf, so it cannot be
redeclared as static in res_debug.c.

Make __p_rcode_syms global and add it to Symbol map. The rest of
__p_??_syms are already global.

Choice of FBSD_1.0 version for these debug symbols seems strange and
should be revisited before symbol  versioning is enabled for libc.so.7.
2007-04-06 19:45:17 +00:00
John Baldwin
5e41bd2cd2 Only reject file descriptors higher than FD_SETSIZE if we are not using
poll(2) or kqueue(2).  Previously we rejected fd's higher than FD_SETSIZE
for kevent(2), and larger than sysconf(_SC_OPEN_MAX) for poll(2).  However,
the check for poll(2) wasn't really needed.  open(2) and socket(2) won't
return an fd you can't pass to either poll(2) or kevent(2).  This fixes
a but where gethostbyname() would fail if you had more than 1023 files
open in a process.

MFC after:	1 week
Reviewed by:	ume
Found by:	ps
2007-03-05 19:39:51 +00:00
Warner Losh
c879ae3536 Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.
2007-01-09 00:28:16 +00:00
Hajimu UMEMOTO
2cd19db26a Merge BIND9 9.3.3 into main chunk.
Obtained from:	ISC
MFC after:	1 week
2006-12-15 20:59:55 +00:00
Hajimu UMEMOTO
3f25740ec6 Vendor import of BIND 9.3.3 2006-12-15 20:49:44 +00:00
Hajimu UMEMOTO
b021e5e1ed Merge res_send.c of BIND9 9.3.3rc2 into main chunk. It includes
following fix:

	Retransmission timeouts should be based on which attempt
	it is to the nameserver and not the nameserver itself.

Obtained from:	ISC
MFC after:	3 days
2006-10-24 14:41:43 +00:00
Hajimu UMEMOTO
7c35eabcb2 Import of BIND 9.3.3rc2 2006-10-24 14:25:49 +00:00
Hajimu UMEMOTO
45c89f1e05 Check if the filedes of kevent is expected one. Though our
old resolver opened just one socket, BIND9's resolver may
open more than one sockets.  And, BIND9's resolver doesn't
close the socket on timeout.  So, we need this check.

Reported by:	freebsd-cvs-src__at__oldach.net (Helge Oldach), bz
Hinted by:	rwatson
2006-08-04 12:26:07 +00:00
Hajimu UMEMOTO
500fe2a19c _close() should be called instead of close() here. 2006-08-04 10:21:11 +00:00
Hajimu UMEMOTO
473c8b2ecf Nuke some compatibility crufts of resolver for 6.X and earlier.
X-MFC after:	never
2006-05-21 11:29:26 +00:00
Hajimu UMEMOTO
d808369aa1 Upgrade res_update(3) and the friends to BIND9's one excluding TSIG
support.

X-MFC after:	never
2006-05-21 11:19:36 +00:00
Hajimu UMEMOTO
f62c4786e1 Vendor import of BIND 9.3.2 2006-05-21 11:10:07 +00:00
Hajimu UMEMOTO
135a67244d This commit was generated by cvs2svn to compensate for changes in r158782,
which included commits to RCS files with non-trunk default branches.
2006-05-21 11:10:07 +00:00
Hajimu UMEMOTO
f76963aba1 Don't test if RES_INIT is set to see res_state structure is
initialized.  Some application may reset RES_INIT.  Use the
way in __res_vinit(), instead.
2006-04-08 18:19:35 +00:00
Hajimu UMEMOTO
eb27a220f8 Expose res_update and friends again. At least, ports/mail/spamilter
uses them.
Now, we have res_nupdate and res_nmkupdate as well, but they are
still based on our old resolver for binary backward compatibility.
So, they don't provide new features such as TSIG support.

Reported by:	pointyhat via kris
2006-03-30 20:15:53 +00:00
Daniel Eischen
4c6aab055d Add __collate_load_error and __collate_range_cmp to the list of
FBSDprivate locale symbols.  These functions are needed by
libcompat.

Add _cleanup to the list of stdio FBSDprivate symbols.  Some
third party applications use this.  This will be removed and
replaced by fcloseall() once libc version is bumped.

Add _res to the list of resolv symbols.

Found by:	portbuilder runs (thanks Kris!)
2006-03-30 04:37:08 +00:00
Hajimu UMEMOTO
aebc6ec293 When res_nquerydomain() returns SERVFAIL, we should try next domain. 2006-03-24 13:30:10 +00:00
Dag-Erling Smørgrav
3a51513f8b It's not enough to provide symbol map files; you also have to add them
to ${SYM_MAPS}.  This unbreaks world with SYMVER_ENABLED.

Pointy hat to:	ume
2006-03-23 16:55:13 +00:00