Skip to content

fix(cli): check strchr return for NULL before dereference in -O handler#527

Open
somethingwithproof wants to merge 1 commit intoCacti:developfrom
somethingwithproof:fix/option-null-deref
Open

fix(cli): check strchr return for NULL before dereference in -O handler#527
somethingwithproof wants to merge 1 commit intoCacti:developfrom
somethingwithproof:fix/option-null-deref

Conversation

@somethingwithproof
Copy link
Copy Markdown
Contributor

When -O is passed without a colon separator, strchr returns NULL. The next line dereferences it unconditionally, causing a segfault. Add NULL check before dereference.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Copilot AI review requested due to automatic review settings April 8, 2026 19:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 CLI crash in spine when -O/--option is provided without a : separator by guarding against strchr() returning NULL.

Changes:

  • Add a NULL check before dereferencing the pointer returned by strchr() in -O/--option parsing.
Comments suppressed due to low confidence (1)

spine.c:426

  • The && *value clause is redundant here: when value != NULL, value points at the ':' character, so *value is always non-zero. If the intent is to validate that both setting and value are present (per --option=S:V), consider checking that there is at least one character after the ':' (e.g., value[1] != '\0') and optionally that setting is non-empty before calling set_option(); otherwise simplify the condition to just if (value != NULL) to avoid implying stronger validation than is actually performed.
			if (value != NULL && *value) {
				*value++ = '\0';
			} else {
				die("ERROR: -O requires setting:value");
			}

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

@somethingwithproof
Copy link
Copy Markdown
Contributor Author

Code-reviewed as part of a batch with #525-#531. These 7 atomic bug fixes are independent of each other and can be merged in any order; recommend bundling into a single dated release. The Windows/CMake work in #523/#524 should follow this batch, and #512 (production CI pipeline) should be split into smaller PRs before review.

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