Skip to content

fix: address argument parsing silent drops - #817

Open
kaahos wants to merge 6 commits into
mainfrom
paul.fournillon/fix-argument-parsing-silent-drops
Open

kaahos wants to merge 6 commits into
mainfrom
paul.fournillon/fix-argument-parsing-silent-drops

Conversation

@kaahos

@kaahos kaahos commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?:

Hardens Arguments::parse so malformed or unrecognized profiler options are no longer silently dropped. Known options with an invalid value now raise a hard IllegalArgumentException (matching the existing fjmethodid convention); unrecognized top-level tokens and referencechains sub-option keys are now captured and reported as non-fatal warnings via Log::warn, instead of vanishing with no trace.

Motivation:

Several option parsers grouped their default case with the "enable" branch, so a typo silently enabled a feature instead of failing. For example, mcleanup=xyz (a typo) previously fell through to the same branch as mcleanup=true and silently enabled method cleanup. The user would get a profiler running in a state they never asked for, with zero indication anything was wrong. Other options (cstack, wallsampler, jvmtistacks, lightweight, referencechains) had the same class of bug in the opposite direction, silently coercing typos to a default/disabled state. Unknown top-level tokens and referencechains sub-keys were also dropped entirely, even from the (currently non-functional) warning log path.

Additional Notes:

  • Added a shared parseBoolOption helper for the y/yes/t/true/1 vs n/no/f/false/0 convention used across these options, replacing several duplicated switch(value[0]) blocks that matched on the first character only (another latent bug: mcleanup=tweq used to pass as true).
  • _unknown_arg (single slot) replaced with _unknown_args (vector), so every unmatched token is reported, not just the first.
  • Fixed a call-order bug in execute0 (javaApi.cpp) where Log::open(args) ran after the error check/early-return, so warnings were swallowed whenever a hard error also fired in the same command string.

How to test the change?:

new/updated TEST_F(ArgumentsTest, ...) cases in arguments_ut.cpp, covering every hardened option (both the new hard-error and the still-valid-value cases) plus unknown-token capture. Also updated remoteargs_ut.cpp's RemoteSymbolicationInvalidValue test, which previously asserted the silent-enable bug as correct behavior. It now asserts remotesym=invalid is a parse error.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a security review (run the dd:platform-security-review
    skill, or file a request via the PSEC review form).
    bewaire also runs automatically on every PR.
  • This PR doesn't touch any of that.
  • JIRA: [JIRA-16048]

Unsure? Have a question? Request a review!

@dd-octo-sts

dd-octo-sts Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #36006502904 | Commit: 764c01e | Duration: 17m 12s (longest job)

✅ All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - ✅ - -
8-ibm - ✅ - -
8-j9 ✅ ✅ - -
8-librca - - ✅ ✅
8-orcl - ✅ - -
11 - ✅ - -
11-j9 ✅ ✅ - -
11-librca - - ✅ ✅
17 ✅ ✅ - -
17-graal ✅ ✅ - -
17-j9 ✅ ✅ - -
17-librca - - ✅ ✅
21 ✅ ✅ - -
21-graal ✅ ✅ - -
21-librca - - ✅ ✅
25 ✅ ✅ - -
25-graal ✅ ✅ - -
25-librca - - ✅ ✅

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-09-24 13:54:29 UTC

@dd-octo-sts

dd-octo-sts Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

✅ All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 34bcf56a

@datadog-official

This comment has been minimized.

@kaahos
kaahos marked this pull request as ready for review September 24, 2026 06:56
@kaahos
kaahos requested a review from a team as a code owner September 24, 2026 06:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-24T06:58:18.378081Z 5b8117a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

switch (value[0]) {
case 'j':

P2 Badge Validate the complete wallsampler value

For malformed values beginning with j or a, such as wallsampler=junk or wallsampler=asgct_typo, switching only on value[0] still accepts the option and selects a sampler. This leaves the silent-coercion bug in place for most typos despite rejecting values beginning with other characters; compare the complete value against the supported sampler names before assigning it.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/arguments.cpp Outdated

@datadog-official datadog-official 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.

Bits Code Review: FAIL

The most critical issue is that a rejected command in execute0 can silently close or truncate the active log file because Log::open runs before parse-error validation. Additionally, the bare referencechains option no longer enables reference-chain profiling because the no-value branch was dropped from the argument parser.

Open Bits AI session

🤖 Bits Code Review · Commit 5b8117a · @DataDog review to ask questions

Comment thread ddprof-lib/src/main/cpp/arguments.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/arguments.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/javaApi.cpp
Comment thread ddprof-lib/src/main/cpp/arguments.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/arguments.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/arguments.cpp Outdated
@kaahos
kaahos requested a review from zhengyu123 September 24, 2026 13:38

This branch has not been deployed

No deployments
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.

2 participants