Skip to content

discovery: fix panic in DNS fallback SRV lookup#10914

Open
erickcestari wants to merge 2 commits into
lightningnetwork:masterfrom
erickcestari:fix-panic-discovery
Open

discovery: fix panic in DNS fallback SRV lookup#10914
erickcestari wants to merge 2 commits into
lightningnetwork:masterfrom
erickcestari:fix-panic-discovery

Conversation

@erickcestari

Copy link
Copy Markdown
Collaborator

The fallback SRV lookup type-asserted each DNS Answer record to *dns.SRV
unconditionally. If the response contains a non-SRV record (e.g. an A or
CNAME), the type assertion panics and crashes the daemon. Use the
comma-ok form to skip non-SRV records instead.

Also guard against an empty LookupHost result for the shim, which would
otherwise panic on an out-of-bounds index into addrs.

This is safe to discuss and fix in public. The bug is very unlikely to be
exploitable: triggering it requires either a DNS seeder to serve a
malformed response, or an on-path MITM injecting one (the fallback
response is unauthenticated). A malicious seeder already has far more
direct ways to disrupt a node, and a MITM attack is hard to mount, so the
panic does not meaningfully widen the attack surface.

The fallback SRV lookup type-asserted each DNS Answer record to *dns.SRV
unconditionally. If the response contains a non-SRV record (e.g. an A or
CNAME), the type assertion panics and crashes the daemon. Use the
comma-ok form to skip non-SRV records instead.

Also guard against an empty LookupHost result for the shim, which would
otherwise panic on an out-of-bounds index into addrs.

This is safe to discuss and fix in public. The bug is very unlikely to be
exploitable: triggering it requires either a DNS seeder to serve a
malformed response, or an on-path MITM injecting one (the fallback
response is unauthenticated). A malicious seeder already has far more
direct ways to disrupt a node, and a MITM attack is hard to mount, so the
panic does not meaningfully widen the attack surface.
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses potential stability issues in the DNS fallback SRV lookup mechanism. By replacing unconditional type assertions with safe checks and adding validation for empty lookup results, the changes prevent the daemon from panicking when receiving malformed or unexpected DNS responses.

Highlights

  • Panic Prevention: Updated the DNS fallback SRV lookup to use comma-ok type assertions, preventing crashes when encountering non-SRV records in DNS responses.
  • Bounds Checking: Added a check for empty results in the DNS shim LookupHost to prevent out-of-bounds index panics.
  • Testing: Introduced a new test stub and test cases to verify that non-SRV records are filtered correctly and that empty shim results are handled gracefully.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@erickcestari erickcestari force-pushed the fix-panic-discovery branch from a29264c to 98f5645 Compare June 19, 2026 20:09

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes potential panics in the DNS fallback SRV lookup by handling empty address results and safely skipping non-SRV records using a comma-ok type assertion. It also adds corresponding unit tests and updates the release notes. The reviewer recommended improving the unit tests by verifying that the type assertions on the bootstrapper interface succeed using require.True instead of ignoring the boolean result, which could lead to nil pointer dereferences.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

[][2]string{{target, "soa.lightning.directory"}},
netStub, time.Second,
)
d, _ := bs.(*DNSSeedBootstrapper)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the comma-ok type assertion but ignoring the boolean result (_) can lead to a nil pointer dereference panic on the next line if the assertion fails. It is safer and more idiomatic to assert that the type assertion succeeded using require.True.

Suggested change
d, _ := bs.(*DNSSeedBootstrapper)
d, ok := bs.(*DNSSeedBootstrapper)
require.True(t, ok)
References
  1. Unit tests must always use the require library. (link)

netStub := &fallbackNet{shimAddrs: nil}

bs := NewDNSSeedBootstrapper(nil, netStub, time.Second)
d, _ := bs.(*DNSSeedBootstrapper)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the comma-ok type assertion but ignoring the boolean result (_) can lead to a nil pointer dereference panic on the next line if the assertion fails. It is safer and more idiomatic to assert that the type assertion succeeded using require.True.

Suggested change
d, _ := bs.(*DNSSeedBootstrapper)
d, ok := bs.(*DNSSeedBootstrapper)
require.True(t, ok)
References
  1. Unit tests must always use the require library. (link)

@github-actions github-actions Bot added the severity-high Requires knowledgeable engineer review label Jun 19, 2026
@github-actions

Copy link
Copy Markdown

PR Severity: HIGH (severity-high)

Automated classification | 2 files (excl. tests) | 21 lines changed (excl. tests)

High (1 file):

  • discovery/bootstrapper.go - Gossip protocol / peer discovery bootstrapping logic

Low (1 file):

  • docs/release-notes/release-notes-0.22.0.md - Release notes documentation

Analysis

The primary change is in discovery/bootstrapper.go, which belongs to the discovery/* package responsible for the gossip protocol and peer bootstrapping. This falls into the HIGH severity tier and requires review from a knowledgeable engineer familiar with peer discovery and gossip mechanics.

The test file (discovery/bootstrapper_test.go) adds 128 lines of new test coverage but is excluded from severity classification per policy. The release notes entry is documentation-only (LOW).

No severity bump was triggered: only 2 non-test files changed (threshold: >20) and 21 non-test lines changed (threshold: >500).


To override, add a severity-override-{critical,high,medium,low} label.
<!-- pr-severity-bot -->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

severity-high Requires knowledgeable engineer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant