FIX: Handle malformed TTL at start of line (fixes #1) #10
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/issue-1-malformed-ttl"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR fixes issue #1 where a TTL placed at the beginning of a line caused zone corruption.
Changes:
lib/DNS/Vi.pmto detect when a line starts with a string that looks like a TTL (e.g.,1h). In such cases, it now correctly applies the TTL to the current label instead of creating a new record.nice(): Resolved a regression in thenice()function that causedNot a HASH referenceerrors during record sorting.Review notes (AI-assisted)
Posted on behalf of @heiko — review drafted with Claude (Sonnet 4.6) reviewed and refined under Opus 4.7.
Overview
The PR addresses two distinct bugs:
1hwritten at the start of a zone line was captured as a label, so on the nextnsupdaterecords under the apex could be wiped while bogus records appeared under1h.example.com.nice()regression: A broken Schwartzian transform innice()causedNot a HASH reference. Verified independently:t/30-unicode.tis broken on master (planned 5 tests but ran 1). The fix here is genuinely necessary — not just incidental cleanup.Correctness
nice()fix — correct and necessary. The new pipeline keeps[reversed_label, cloned_rrset]together through the sort and extracts the cloned rrset at the end. Clone semantics preserved.Parser fix — partially correct, with a concrete gap. The detection regex
/^\d+[wdhms]$/imatches only single-unit TTLs (1h,2d). Butnice()emits compound TTLs viattl2h()(e.g. 129600s →1d12h). I reproduced the same data-loss mode the PR is meant to fix:Suggested fix: widen to match the parser's own TTL named-capture pattern, e.g.
/^\d[\dwdhms]*[wdhms]$/i(anchored, must end in a unit so a stray12345label isn't reinterpreted).Other notes
(?=\s)lookahead in the label capture is behaviorally equivalent (backtracking handles it) but unexplained — worth a comment, or revert (the fix doesn't require it).@{+}{qw(...)}is an obscure spelling of@+{qw(...)}. Forces the reader to disambiguate from@+(regex end-positions array). Suggest@+{qw(label ttl rrtype data)}ormy %m = %+;.$last_labelcould in principle be undefined if a TTL-as-label line appears before any record establishes a label. In real zones the SOA always comes first, so unreachable in practice — worth either a defensive check or a comment.Test coverage
t/20-malformed-ttl.tclearly demonstrates the fix (fails on master withgot: '1h.example.com.', passes on the branch).1d12h). Adding one would also pin the widened regex going forward.Verdict
Mergeable as-is for the literal report in #1, but I'd close the compound-TTL gap before merging — it's the same data-loss bug with slightly different input, and
nice()actively produces those compound forms.Will push a follow-up commit widening the regex and adding the compound-TTL test case.
merged into master
Pull request closed