Skip to content

fix: strip inline comments from single-value config sections#7546

Open
pete-csyn wants to merge 2 commits into
XRPLF:developfrom
pete-csyn:fix/config-inline-comment-single-value-sections
Open

fix: strip inline comments from single-value config sections#7546
pete-csyn wants to merge 2 commits into
XRPLF:developfrom
pete-csyn:fix/config-inline-comment-single-value-sections

Conversation

@pete-csyn

Copy link
Copy Markdown

Summary

Inline # comments on a value line crash rippled at startup for single-value config sections, even though the same comments are silently stripped for key = value sections. Fixes #7545.

Problem

parseIniFile() (src/xrpld/core/detail/Config.cpp) treats a line as a comment only if it starts with #. Single-value sections are then read by getSingleSection() and passed straight to beast::lexicalCastThrow<...>(), so a value like:

[peer_private]
1   # refuse unsolicited inbound peering

becomes lexicalCastThrow<bool>("1 # refuse unsolicited inbound peering")beast::BadLexicalCast. Because that derives from std::bad_cast (not std::runtime_error), it escapes as an uncaught terminate, crash-looping the daemon with no line number or section name in the message. key = value sections are unaffected because BasicConfig::Section::append() already strips inline comments (including escaped \#).

Fix

Strip a trailing, unescaped # comment when reading a single-value section, mirroring Section::append's escaped-\# handling. Scoped to getSingleSection() so multi-line sections (already handled by Section::append) are untouched.

This implements option (a) from #7545. Happy to refactor the stripping into a helper shared with Section::append, or switch to option (b) (fail with a clear parse error naming the section/value) if maintainers prefer.

Test

Extends Config_test::testNetworkID with a single-value section carrying a trailing inline comment, asserting it parses (networkId == 1024) instead of throwing. The new case catches std::exception so a regression fails the test rather than aborting the test binary.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Inline '#' comments on a value line crash rippled at startup for
single-value sections (e.g. [peer_private], [ledger_history],
[network_id]): parseIniFile() only discards whole-line comments, so the
value is passed verbatim to lexicalCast and throws beast::BadLexicalCast
(a std::bad_cast, not std::runtime_error) -> uncaught terminate ->
crash-loop, with no line number or section in the message. The same
inline comments are silently stripped for key=value sections via
BasicConfig::Section::append.

Strip a trailing, unescaped '#' comment (matching Section::append's
escaped-'\#' handling) when reading a single-value section, and add a
regression case to Config_test::testNetworkID.

Fixes XRPLF#7545

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a startup crash caused by inline # comments in single-value config sections by stripping trailing, unescaped comments before values are passed to beast::lexicalCastThrow, aligning behavior with the existing key = value parsing path.

Changes:

  • Add removeTrailingComment() in Config.cpp and apply it in getSingleSection() so single-value sections tolerate trailing inline comments (with \# escape handling).
  • Extend Config_test::testNetworkID to cover a single-value section containing a trailing inline comment and ensure it parses successfully.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/xrpld/core/detail/Config.cpp Strip trailing inline # comments (respecting \#) for single-value sections before lexical casting.
src/test/core/Config_test.cpp Add regression coverage for inline comments in [network_id] single-value parsing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// which escaped as an uncaught terminate at startup. Catch
// std::exception so a regression fails the test rather than aborting
// the test binary. See issue #7545.
try

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done — added error.clear(); immediately before the try in testNetworkID (commit edcea92). The new inline-comment case is now self-contained and no longer relies on error being empty from the preceding assertions. Thanks for the catch.

Per Copilot review on PR XRPLF#7546: error is only assigned in the catch
block, so the trailing BEAST_EXPECT(error.empty()) relied on error
already being empty on entry. Clearing it explicitly makes the new
case independent of preceding assertions and robust to future edits.
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.

Config: inline # comments crash rippled (BadLexicalCast) in single-value sections — legacy parseIniFile path doesn't strip them

2 participants