Commit Graph

3644 Commits

Author SHA1 Message Date
Ludovic Fernandez 906238edc6 fix: panicing on options parsing. (#642) 2018-03-01 06:22:09 -08:00
Tom Thorogood 4d25966dce Test that Shutdown does not surface closed errors (#624)
* Test that Shutdown does not surface closed errors

This test checks that calling Shutdown does not cause ActivateAndServe
(via serveTCP and serveUDP) to return the underlying
'use of closed network connection' error.

This commit unifies TestShutdownTCP with TestShutdownUDP. After this
commit, both tests will check that ActivateAndServe returns a nil error
and that Shutdown succeeded.

This was previously broken for serveTCP.

* Add comment explaining why fin chan is buffered
2018-02-27 17:38:12 -08:00
Miek Gieben 5364553f1e Release 1.0.4 2018-01-25 10:38:03 +00:00
Miek Gieben 43913f2f4f
Fix for CVE-2017-15133 TCP DOS (#631)
serveTCP calls reader.ReadTCP in the accept loop rather than in
the per-connection goroutine. If an attacker opens a connection
and leaves it idle, this will block the accept loop until the
connection times out (2s by default). During this time no other
incoming connections will succeed, preventing legitimate queries
from being answered.

This commit moves the call to reader.ReadTCP into the per-connection
goroutine. It also adds a missing call to Close whose absence allowed
file-descirptors to leak in select cases.

This attack and fix have no impact on serving UDP queries.
2018-01-25 10:36:19 +00:00
Frank Denis 862243b3b1 Add dnscrypt-proxy and rpdns to the list of users (#628) 2018-01-17 20:57:19 +00:00
Tom Thorogood f5ac34d755 Fix TCP Shutdown 'use of closed network connection' (#623)
The check for srv.started being false is in the wrong place, it should
be after Accept not after ReadTCP. If Shutdown is called, serveTCP will
currently return a 'use of closed network connection' error, which is
undesired.

This commit mirrors the behaviour of serveUDP with respect to Shutdown.
2018-01-10 13:37:59 +00:00
Miek Gieben 9cef7a0d3d Release: plain push is also needed
Apparently a git push --tags doesn't push all the changes!?!
Adding plain "git push" to avoid release confusion.
2018-01-10 08:17:22 +00:00
Miek Gieben 5ec25f2a50 Release 1.0.3 2018-01-10 08:11:11 +00:00
Tom Thorogood ddd8477be2 Ignore malformed UDP datagrams without headers (#622)
Ignore malformed UDP datagrams with incomplete DNS headers
2018-01-10 07:51:00 +00:00
Tom Thorogood 69d25e845f Fixes #613 & #619 (#621)
* Do not reutrn ErrShortRead in readUDP

A read of zero bytes indicates a peer shutdown for TCP sockets -- and
thus returning ErrShortRead is fine in readTCP -- but not for UDP
sockets. For UDP sockets a read of zero bytes literally indicates a
zero-byte datagram, and is a valid return value not indicating an error.

Removing this case will cause readUDP to correctly return a zero-byte
message.

* Return non-temporary error from serveUDP loop

Fixes #613
2018-01-09 13:57:26 +00:00
Miek Gieben e2db8456df
Revert "Fixes #613 (#617)" (#620)
This reverts commit ac8cd7878c.
2018-01-09 08:03:27 +00:00
Miek Gieben dcdbddd810
ClassANY: don't convert CLASS255 to ANY (#618)
* ClassANY: don't convert CLASS255 to ANY

Class "ANY" is wireformat only. In zonefile you can use CLASS255, but
when String-ing we convert this into "ANY" which is wrong. I.e. this
means we can't read back our own update.

Bit of a kludge to work around this, as I'm not sure we can just remove
ANY from the ClassToString map.
2018-01-07 17:57:04 +00:00
Twitch ac8cd7878c Fixes #613 (#617)
* Fixes #613

* use net.Error interface for detecting temporary errors
2018-01-06 16:01:19 +00:00
Miek Gieben afd3e95dbb
test: remove net tests (#616)
Never executed, flaky and failing now that some SIDN test servers
have been removed.

Just delete the code; hopefully we can bring it back one day in a CI
repo or something?
2018-01-05 13:11:23 +00:00
Miek Gieben 787fb05a25 Release 1.0.1 2017-12-21 11:36:42 +00:00
Lorenz Bauer 9088876525 Don't use untrusted lengths from Header to pre-allocate (#610)
We currently use information from a potential attacker to pre-allocate slices for the Question, Answer, etc. sections. This allows an attacker to force allocation of several MiB per parsed Msg.

Instead, don't pre-allocate those slices. append() always allocates in powers of two, which is probably the best we can do.

Fixes #609.
2017-12-21 10:24:07 +00:00
Miek Gieben 5f2d7c7013
Unpack: return header (#608)
When we unpack a message and only have the header consider it a valid
message and don't return an error.
2017-12-20 10:51:13 +00:00
Matthijs Mekking cef5150e02 Fix issue #605 (#606)
This makes `client.Readmsg` always return the message,
regardless if and how unpacking the message failed.
2017-12-18 20:15:56 +00:00
Miek Gieben 3bbde607ac
relative include: now tested! (#602)
* relative include: now tested!

If you take the effort of creating includePath, actually use it when
opening the file. Now tested (again) with CoreDNS (with a zone file that
includes two others)

Failure to include leads to:

~~~
2017/12/07 16:47:00 plugin/file: /tmp/example.org: dns: failed to include `a/1include1.org' as `/tmp/a/1include1.org': "a/1include1.org" at line: 15:24
~~~

* dont change the error line
2017-12-07 17:12:20 +00:00
Miek Gieben c438b740fe
Allow $INCLUDE to reference relative file (#598)
When using a relative file in an $INCLUDE the file is referenced from
the cwd from the calling processes; this changes it to be down from the
view point where the file exists.

Code from https://github.com/miekg/dns/issues/537#issuecomment-342932962

Fixes #537
2017-12-06 22:03:54 +00:00
Miek Gieben 6d3b6dc31b
Add size-hex: modifier for len() (#599)
This was missing and generated the wrong code for TKEY; it adds a +1 to
the amount. This should happen (technically).

I think the fallout is not super bad (of the +1) as we allocate a byte
more for when pack a message.
2017-12-06 21:41:53 +00:00
Miek Gieben e508eecd67
Some linter fixes from Go report card. (#601)
Implement small linter fixes.
2017-12-06 11:31:56 +00:00
Miek Gieben 862c2faf96
Add codecov yaml to not fail the build (#600) 2017-12-06 10:36:23 +00:00
Miek Gieben fbee4ceea9
Lint: use ignore-this on generated files (#596)
Make golint not complain about generated file - it's a bit of cheating,
but I think that is OK.
2017-12-06 10:02:47 +00:00
Miek Gieben 9271f6595b
Add semver (#595)
Add a version.go that has the semver version of this libary; now at
1.0.0. Use a struct so external code can easily check the for the
version without resulting to string parsing. Add String() function if
you want to access the version string.

Use simple Makefile.release to kick off a new release:

% edit version.go
% make -f Makefile.release

will tag and push according to version, if version is 1.0.0 the tag
in git will be v1.0.0
2017-12-06 09:46:54 +00:00
James Hartig 325e98bb86 Use and vendor golang.org/x/net/ipv4 and golang.org/x/net/ipv6 (#594) 2017-12-04 09:59:24 +00:00
Miek Gieben 6da3249dfb
EDNS0 client subnet: drop draft option (#589)
Noone should be using this option, it has been deprecated ever since
RFC 7178 came out: May 2016. Remove code that deals with that.
2017-11-28 07:48:19 +00:00
spsholleman 052efef004 Add support for TKEY RRs (#567)
* Add support for TKEY RRs

- make sure Key and Data fields are variable length hex fields
- checkin output from 'go generate'
- add a TKEY specific test to ensure this stays working

* go format changes

* address review comments

* add ability to parse TKEY via string

* handle review comments - change TKEY string output
2017-11-28 07:48:02 +00:00
Marc Ende 5ec0c6d20f Modified clientconfig to match ndots0 (#590)
* Modified clientconfig to match ndots0

* Added Tests for reading resolv.conf

* Cleaned up and removed duplicated code in test

* Added test for ndots below 0

* Cleaned up test

* Clean up
2017-11-27 11:17:45 +00:00
Miek Gieben 57a0d1a2cf
458+dep (#591)
* Add support for Ed25519 DNSSEC signing from RFC 8080

Note: The test case from RFC 8080 has been modified
to correct the missing final brace, but is otherwise
present as-is.

* Explain why ed25519 is special cased in (*RRSIG).Sign

* Explain use of ed25519.GenerateKey in readPrivateKeyED25519

* Add dep

This is PR #458 with the dependency added into it.
2017-11-27 10:49:53 +00:00
Miek Gieben 79bfde677f
Include missing types when for DNSSEC sig verify (#587)
rawSignatureData currently missed a few types:
MD MF RP AFSDB RT SIG PX NXT A6

We don't have NXT and A6 anymore in this lib. Add the other ones.

Fixes #523
2017-11-25 08:20:28 +00:00
Miek Gieben 2ae4695cc7
Implement CSYNC (#585)
Implement the CSYNC record.

Fixes #290

Long overdue, lets add this record. Similar in vain as NSEC/NSEC3, we
need to implement len() our selves. Presentation format parsing and
tests are done as well.

This is CoreDNS running with CSYNC support, `dig` doesn't support this
at the moment, so:

~~~
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40323
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;csync.example.org.		IN	TYPE62

;; ANSWER SECTION:
csync.example.org.	10	IN	TYPE62	\# 12 000335240042000460000008

;; AUTHORITY SECTION:
example.org.		10	IN	NS	a.iana-servers.net.
example.org.		10	IN	NS	b.iana-servers.net.
~~~
2017-11-25 08:19:06 +00:00
Miek Gieben e776a21550
Remove idn/ (#584)
Superseded by x/net/idna. It was useful, but not anymore; remove
entire directory.

Fixes #518
2017-11-25 08:18:44 +00:00
JeremyRand cdb76b64a3 Spelling fixes (#583)
* Doc: fix misspelling.

Found via "misspell" static analyzer.

* Parse test: fix misspellings.

Found via "misspell" static analyzer.
2017-11-24 08:14:48 +00:00
Miek Gieben be5ae6ca7a
Add fuzzing framework (#580)
Add easy way to fuzz this dns library, put fuzz related code in fuzz.go
and have a small Makefile.fuzz to be used:

$ make -f Makefile.fuzz build
$ make -f Makefile.fuzz fuzz

Will build and fuzz the library. Both pack/unpack and NewRR are fuzz
targets, but we could open this up.
2017-11-23 09:34:31 +00:00
Miek Gieben acff9ce3fa
Fuzzing the text parser: a few fixes (#579)
I'm fuzzing the text parser and that turned up these two. Will do
further fuzzing with these fixes in.
2017-11-20 18:07:37 +00:00
Miek Gieben 7994cb36ea
Test: rework concurrentExchange (#576)
See issue #575. Try to fix (and maybe trigger it)
2017-11-17 15:31:51 +00:00
Matthijs Mekking 99c447f9f6 TSIG name must be presented in canonical form (#574)
* TSIG name must be presented in canonical form

Update the documentation to make clear that the zonename in the
TsigSecret map must be in canonical form.

* Reference RFC 4034 for canonical form
2017-11-17 13:17:47 +00:00
Miek Gieben 2a67631d76
cleanup: remove debug.Printf from scanner (#573)
Remove the debug.Printf stuff from scanner and some other style nits.
2017-11-17 10:48:42 +00:00
Miek Gieben cfe41281c2
txt parser: fix goroutine leak (#570)
* txt parser: fix goroutine leak

When a higher level (grammar or syntax) error was encountered the lower
level zlexer routine would be left open and trying to send more tokens
on the channel c. This leaks a goroutine, per failed parse...

This PR fixes this by signalling this error - by canceling a context -
retrieving any remaining items from the channel, so zlexer can return.

It also adds a goroutine leak test that can be re-used in other tests,
the TestParseBadNAPTR test uses this leak detector.

The private key parsing code had the same bug and is also fixed in this
PR.

Fixes #586
Fixes https://github.com/coredns/coredns/issues/1233

* sem not needed anymore
2017-11-17 10:47:28 +00:00
Miek Gieben 9fc4eb252e
Server: drop inflight waitgroup (#561)
* Server: drop inflight waitgroup

This drops the waitgroup in Server, the suspicion is this can make the server
fail to stop; doing this make graceful shutdown not work.

Add test that tries to find a race between starting on stopping race;
there was a data race on srv.Inflight.

The coredns' TestReadme doesn't race anymore with this as it did with
the more evasive PR #546.
2017-11-10 10:33:17 +00:00
Miek Gieben 9cfd42f1df
Tests: add ListenAndServe tests (#562)
This increases the test coverage as these methods where not tested.
Add some cosmetic changes to the mix.
2017-11-10 10:11:23 +00:00
Miek Gieben 4bb60ce4d8
Revert "server: drop graceful handling (#546)" (#560)
This reverts commit 8223ae840e.
2017-11-09 21:01:09 +00:00
Miek Gieben 8223ae840e
server: drop graceful handling (#546)
Drop all graceful handling. There is just too much locking in
waitgrouping going on for very little gain; deal with it.

Make the error handling between serve{TCP,UDP} identical.
2017-11-09 09:38:14 +00:00
Tom Limoncelli 7e7e8dcb22 util.TrimDomainName() fails when origin doesn't end in dot (#559)
* Fix https://github.com/miekg/dns/issues/555 dnsutil.TrimDomainName tests fail

* Remove comment

* Clean up comments and code.

* Clean up comments, use dns.Fqdn() where we can, lint.
2017-11-08 18:19:10 +00:00
Miek Gieben 388f6eea29
Tests updates (#556)
Use :0 for loopback testing. This is more portable between testing environments.
Add testRR that calls NewRR and throws error away - apply it everywhere where needed.

It seems only Go 1.9 can deal with :0 being used. Disable 1.8 in travis.
2017-11-08 10:01:19 +00:00
Miek Gieben 813f928d53
readme: small bunch updates (#554)
Remove specifying the versions of Go, just say the last two, this is
getting stale every single time.
2017-11-07 17:37:25 +00:00
Miek Gieben 4bcc48899c
golint fixes (#553)
* golint fixes

Comment all RR with references to relevant RFC or other docs.
Some lint fixes in edns0.go.

* Some more fixes
2017-11-07 13:45:27 +00:00
Miek Gieben f73262699a
Add goreportcard badge (#552) 2017-11-07 11:23:24 +00:00
Miek Gieben 13c92255fe
codecov: add shield to README (#551) 2017-11-07 09:35:32 +00:00