Skip to content

fix(config): handle malformed prep_cmd and dd_mode_remapping JSON in config - #5500

Open
Rohan-Vij wants to merge 1 commit into
LizardByte:masterfrom
Rohan-Vij:fix/config-json-parse-crash
Open

fix(config): handle malformed prep_cmd and dd_mode_remapping JSON in config#5500
Rohan-Vij wants to merge 1 commit into
LizardByte:masterfrom
Rohan-Vij:fix/config-json-parse-crash

Conversation

@Rohan-Vij

Copy link
Copy Markdown

Description

The existing try/catch for loading the config file (apply_config()) only catches filesystem-level errors, not JSON schema errors. If either of the two JSON blobs (stored as strings) in the config file (global_prep_cmd, dd_mode_remapping) is malformed, they are not caught by the catch clauses, and Sunshine never starts up until the typo/error is fixed. Because the web UI does not currently have input validation, this error is likely to occur. The fix catches JSON parsing issues specifically either in global_prep_cmd or dd_mode_remapping and returns the default for either config if malformed, letting Sunshine start with a malformed config (which can be reported in logging).

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

See our AI usage policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

read_json/get_child throw ptree_error (json_parser_error or
ptree_bad_path), which derive from std::runtime_error rather than
filesystem_error. config::parse() only guards apply_config() with
filesystem_error handlers, so a malformed global_prep_cmd or
dd_mode_remapping value escaped to main() and terminated the process.
Because the bad value is persisted in the config, Sunshine then failed
to start on every launch (crash loop).

Wrap the JSON parsing in list_prep_cmd_f() and mode_remapping_from_view()
so an invalid value is logged and skipped (falling back to the default)
instead of aborting startup. Add tests/unit/test_config.cpp covering the
malformed, missing-key, and valid parse paths for both helpers.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3 New issues
3 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

1 participant