Skip to content

fix: Assert connection is loaded in PeerReservationTable mutators#7828

Open
SAY-5 wants to merge 2 commits into
XRPLF:developfrom
SAY-5:ci/peer-reservation-null-connection-guard
Open

fix: Assert connection is loaded in PeerReservationTable mutators#7828
SAY-5 wants to merge 2 commits into
XRPLF:developfrom
SAY-5:ci/peer-reservation-null-connection-guard

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jul 18, 2026

Copy link
Copy Markdown

High Level Overview of Change

PeerReservationTable::connection_ is a raw pointer initialized to nullptr and only set later by load(). Both insertOrAssign() and erase() dereference it unconditionally (connection_->checkoutDb()), so calling either before load() runs would be an unchecked null dereference. This adds an XRPL_ASSERT(connection_, ...) at the top of both mutators to make the "must be loaded first" precondition explicit, consistent with how the rest of the overlay code guards its invariants. Fixes #7509.

Context of Change

In normal startup load() is called during ApplicationImp::setup before any RPC handler can reach these methods, so this is a defensive guard rather than a fix for an observed crash. The assertion documents and enforces the ordering invariant, and turns a would-be null dereference into a clear diagnostic in debug builds.

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

Test Plan

The added assertions only fire when the invariant is violated (mutator called before load()), which the existing peer-reservation tests never do, so those tests continue to pass unchanged and no new test is needed for the guarded path. The change is formatted with the repository .clang-format.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@github-actions

Copy link
Copy Markdown

⚠️ This PR contains unsigned commits. To get your PR merged, please sign them. ⚠️

If only the most recent commit is unsigned, you can run:

  1. Amend the commit: git commit --amend --no-edit -n -S
  2. Overwrite the commit: git push --force-with-lease

If multiple commits are unsigned, you can run:

  1. Go into interactive rebase mode: git rebase --interactive HEAD~<NUM_OF_COMMITS>, where NUM_OF_COMMITS is the number of most recent commits that will be available to edit.
  2. Change "pick" to "edit" for the commits you need to sign, and then save and exit.
  3. For each commit, run: git commit --amend --no-edit -n -S
  4. Continue the rebase: git rebase --continue
  5. Overwrite the commit(s): git push --force-with-lease

If you're new to commit signing, there are different ways to set it up:

Sign commits with gpg

Follow the steps below to set up commit signing with gpg:

  1. Generate a GPG key
  2. Add the GPG key to your GitHub account
  3. Configure git to use your GPG key for commit signing
Sign commits with ssh-agent

Follow the steps below to set up commit signing with ssh-agent:

  1. Generate an SSH key and add it to ssh-agent
  2. Add the SSH key to your GitHub account
  3. Configure git to use your SSH key for commit signing
Sign commits with 1Password

You can also sign commits using 1Password, which lets you sign commits with biometrics without the signing key leaving the local 1Password process.
See use 1Password to sign your commits.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PeerReservationTable null pointer dereference if used before load()

1 participant