<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/two-bugs-later-what-it-actually-took-to-replace-a-dns-library-tj1tpd3ax" -->

---
title: Two Bugs Later: What It Actually Took to Replace a DNS...
description: A Go developer built hollow, a zero-dependency recursive DNS resolver, to see what replacing the widely-used miekg/dns library (16,234 importers) actually...
canonical: https://daily.dev/posts/two-bugs-later-what-it-actually-took-to-replace-a-dns-library-tj1tpd3ax
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Two Bugs Later: What It Actually Took to Replace a DNS Library | daily.dev
og:description: A Go developer built hollow, a zero-dependency recursive DNS resolver, to see what replacing the widely-used miekg/dns library (16,234 importers) actually...
og:url: https://daily.dev/posts/two-bugs-later-what-it-actually-took-to-replace-a-dns-library-tj1tpd3ax
og:image: https://api.daily.dev/og/posts/tj1TPd3ax.png
og:image:alt: Two Bugs Later: What It Actually Took to Replace a DNS Library
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Two Bugs Later: What It Actually Took to Replace a DNS Library

**[DEV](https://daily.dev/sources/devto)** · 14 min read · 3 upvotes · 1 comments

## Summary

A Go developer built hollow, a zero-dependency recursive DNS resolver, to see what replacing the widely-used miekg/dns library (16,234 importers) actually costs. The project totals 9,984 lines of Go plus 11,033 lines of tests. Writing the DNS codec was straightforward since the format is well documented, but the resolver shipped with two serious bugs: a case-folding compression key bug that broke the resolver's own anti-spoofing case-randomization defense, and a label-joining bug that let a single label containing a dot collide with a two-label sequence, both exploitable from the network. A third one-line bug, using strings.HasSuffix for bailiwick checking, opened a cache-poisoning hole because escaped dots in labels defeat naive suffix matching. Go's native fuzzer (testing.F), asserting a round-trip property rather than just checking for crashes, caught both codec bugs after 38.4 million executions. The piece also covers a termination proof for compression-pointer loops, decisions a library normally makes silently (UDP packet dropping, rate-limit truncation vs refusal, TTL rewriting, blocklist parsing pitfalls), and gaps where Go's standard library falls short (terminal size detection, DNSSEC). The author concludes most developers should just use miekg/dns unless eliminating the dependency itself is the actual goal.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://dev.to/shashank_chauhan_893459b2/two-bugs-later-what-it-actually-took-to-replace-a-dns-library-2k2n>

## Questions this post answers

### Why is using strings.HasSuffix to check DNS bailiwick (whether a nameserver is authoritative for a name) insecure?

A suffix string comparison can be tricked by escaped dots inside a DNS label. A label like evil\.com is a single label and a sibling of com, not a child of it, but its raw bytes still end in com., so strings.HasSuffix wrongly accepts glue records for ns1.evil\.com inside a com referral. The fix is to unescape into labels and compare label-by-label from the right, which costs an extra allocation per call but rejects the forged case; this class of bug is a textbook cache-poisoning vector.

_Anyone hardening a DNS resolver against cache poisoning can track write-ups like this via daily.dev._

### How can a Go fuzz test (testing.F) catch DNS message encoding bugs that code review and unit tests miss?

By asserting a round-trip property instead of just checking for crashes: anything the decoder decodes must re-encode, decode again to an identical message, and encode a second time to identical bytes. A rewritten name from a compression-pointer collision breaks that fixed point immediately. This approach found two case-sensitivity and label-boundary bugs in a DNS codec after 38.4 million fuzz executions, with no build tag or separate corpus tooling needed.

_Developers weighing fuzz testing strategies for protocol code can find similar deep dives on daily.dev._

### Why does checking that a DNS compression pointer only points backwards fail to prevent infinite loops when decoding a message?

Because a pointer jumping backwards is not sufficient on its own: after the jump, the label walk moves the cursor forward again, so a pointer at offset 20 targeting offset 15 can walk forward from 15 back to offset 20, looping forever despite satisfying the backwards rule. The fix compares each pointer against the previous pointer's target rather than the current read position, forcing targets into a strictly decreasing sequence that must terminate.

_Engineers debugging malformed-packet handling in custom parsers can follow similar deep dives on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@agustinbarrientos** · 0 upvotes

> Did the 41-row decision table go into the PR too? I'd keep it open beside the diff. Otherwise I wouldn't know which weird DNS behavior was intentional.

## Similar posts on daily.dev

- [Issue \#621: Why Go had to hardcode a block on broken certs — Go Weekly](https://daily.dev/posts/issue-621-why-go-had-to-hardcode-a-block-on-broken-certs-go-weekly-nsgai3qmu) · Golang Weekly · 2 upvotes · 0 comments
- [Popular Go Decimal Library Targeted by Long-Running Typosqua...](https://daily.dev/posts/popular-go-decimal-library-targeted-by-long-running-typosqua--5muxkobmf) · Socket · 28 upvotes · 0 comments
- [Can it Resolve DOOM? Game Engine in 2,000 DNS Records – blog.rice.is](https://daily.dev/posts/can-it-resolve-doom-game-engine-in-2-000-dns-records-blog-rice-is-4vuxc4vsw) · Lobsters · 4 upvotes · 1 comments

---

Tags: [#security](https://daily.dev/tags/security), [#open-source](https://daily.dev/tags/open-source), [#golang](https://daily.dev/tags/golang), [#dns](https://daily.dev/tags/dns)

[View this post on daily.dev](https://daily.dev/posts/two-bugs-later-what-it-actually-took-to-replace-a-dns-library-tj1tpd3ax)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Two Bugs Later: What It Actually Took to Replace a DNS Library","url":"https://daily.dev/posts/two-bugs-later-what-it-actually-took-to-replace-a-dns-library-tj1tpd3ax","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/two-bugs-later-what-it-actually-took-to-replace-a-dns-library-tj1tpd3ax"},"datePublished":"2026-09-08T18:06:34.689Z","dateModified":"2026-09-08T18:07:04.353Z","description":"A Go developer built hollow, a zero-dependency recursive DNS resolver, to see what replacing the widely-used miekg/dns library (16,234 importers) actually...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4c4b79ffa09a53c137284e2350ac55dc?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4c4b79ffa09a53c137284e2350ac55dc?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"DEV","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"DEV","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/devto","url":"https://daily.dev/sources/devto"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/two-bugs-later-what-it-actually-took-to-replace-a-dns-library-tj1tpd3ax","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"security,open-source,golang,dns","timeRequired":"PT14M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"DEV","item":"https://daily.dev/sources/devto"},{"@type":"ListItem","position":3,"name":"Two Bugs Later: What It Actually Took to Replace a DNS Library"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/two-bugs-later-what-it-actually-took-to-replace-a-dns-library-tj1tpd3ax","comment":[{"@type":"Comment","text":"Did the 41-row decision table go into the PR too? I’d keep it open beside the diff. Otherwise I wouldn’t know which weird DNS behavior was intentional.","datePublished":"2026-09-09T16:16:48.515Z","url":"https://daily.dev/posts/tj1TPd3ax#c-VbGhEEb3D","author":{"@type":"Person","name":"Agustin Barrientos","url":"https://daily.dev/agustinbarrientos","image":"https://media.daily.dev/image/upload/s--5ayxQnqn--/f_auto/v1788281802/avatars/avatar_wQYYVe5Tbj0NJ7C7qPoa8?_a=BAMAMicg0"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/two-bugs-later-what-it-actually-took-to-replace-a-dns-library-tj1tpd3ax#faq","mainEntity":[{"@type":"Question","name":"Why is using strings.HasSuffix to check DNS bailiwick (whether a nameserver is authoritative for a name) insecure?","acceptedAnswer":{"@type":"Answer","text":"A suffix string comparison can be tricked by escaped dots inside a DNS label. A label like evil\\.com is a single label and a sibling of com, not a child of it, but its raw bytes still end in com., so strings.HasSuffix wrongly accepts glue records for ns1.evil\\.com inside a com referral. The fix is to unescape into labels and compare label-by-label from the right, which costs an extra allocation per call but rejects the forged case; this class of bug is a textbook cache-poisoning vector. Anyone hardening a DNS resolver against cache poisoning can track write-ups like this via daily.dev."}},{"@type":"Question","name":"How can a Go fuzz test (testing.F) catch DNS message encoding bugs that code review and unit tests miss?","acceptedAnswer":{"@type":"Answer","text":"By asserting a round-trip property instead of just checking for crashes: anything the decoder decodes must re-encode, decode again to an identical message, and encode a second time to identical bytes. A rewritten name from a compression-pointer collision breaks that fixed point immediately. This approach found two case-sensitivity and label-boundary bugs in a DNS codec after 38.4 million fuzz executions, with no build tag or separate corpus tooling needed. Developers weighing fuzz testing strategies for protocol code can find similar deep dives on daily.dev."}},{"@type":"Question","name":"Why does checking that a DNS compression pointer only points backwards fail to prevent infinite loops when decoding a message?","acceptedAnswer":{"@type":"Answer","text":"Because a pointer jumping backwards is not sufficient on its own: after the jump, the label walk moves the cursor forward again, so a pointer at offset 20 targeting offset 15 can walk forward from 15 back to offset 20, looping forever despite satisfying the backwards rule. The fix compares each pointer against the previous pointer's target rather than the current read position, forcing targets into a strictly decreasing sequence that must terminate. Engineers debugging malformed-packet handling in custom parsers can follow similar deep dives on daily.dev."}}]}
```

