Skip to content

Properly handle potential NULL-deref issues#1996

Merged
BenBE merged 2 commits into
htop-dev:mainfrom
BenBE:optarg-asserts
May 15, 2026
Merged

Properly handle potential NULL-deref issues#1996
BenBE merged 2 commits into
htop-dev:mainfrom
BenBE:optarg-asserts

Conversation

@BenBE

@BenBE BenBE commented May 15, 2026

Copy link
Copy Markdown
Member

While the value of optarg semantically is non-zero for required arguments, this isn't obvious for static code analyzers. Thus this PR first adds the missing asserts to make this consistent, before then upgrading those to full-on argument parsing failures.

Ref: Coverity issue CID 645928.

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation of command-line arguments for the sort-key, delay, max-iterations, and filter options. The app now checks that required values are provided and returns a clear error when arguments are missing, preventing crashes or undefined behavior.

Review Change Stack

@BenBE BenBE added this to the 3.6.0 milestone May 15, 2026
@BenBE BenBE added the code quality ♻️ Code quality enhancement label May 15, 2026
@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 52c5812a-e378-4177-9b4a-cf37bdb3d8d6

📥 Commits

Reviewing files that changed from the base of the PR and between d81043e and 18fcb1a.

📒 Files selected for processing (1)
  • CommandLine.c

📝 Walkthrough

Walkthrough

This PR updates CommandLine.c to validate that optarg is non-NULL for four options: -s/--sort-key, -d/--delay, -n/--max-iterations, and -F/--filter. Each affected case now returns STATUS_ERROR_EXIT immediately when optarg is missing; two previously used assert(optarg) are replaced with runtime checks.

Poem

🐰 I hop through args with careful cheer,

I sniff for NULL where once was fear,
Four flags now guard their trailing bit,
If none is found, I bail—quickly quit,
A tidy exit, carrot-approved, hop-sweet!

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

@BenBE BenBE marked this pull request as ready for review May 15, 2026 00:03
@BenBE BenBE force-pushed the optarg-asserts branch from d81043e to 18fcb1a Compare May 15, 2026 00:12
@BenBE BenBE merged commit b7f9df9 into htop-dev:main May 15, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality ♻️ Code quality enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant