Skip to content

system/settings: Bound settings string handling#3505

Open
nightt5879 wants to merge 2 commits into
apache:masterfrom
nightt5879:nightt5879/bound-settings-strings-3109
Open

system/settings: Bound settings string handling#3505
nightt5879 wants to merge 2 commits into
apache:masterfrom
nightt5879:nightt5879/bound-settings-strings-3109

Conversation

@nightt5879
Copy link
Copy Markdown
Contributor

Summary

Fixes #3109.

This PR bounds string handling in system/settings where the maximum field sizes are already defined by Kconfig.

Commit structure:

  • Commit 1 (system/settings: Bound public string handling) updates the public settings paths to validate key/value/file strings with strnlen() before scanning, compare fixed-size keys with strncmp(), and copy into fixed-size fields with strlcpy().
  • Commit 2 (system/settings: Bound storage string handling) applies the same bounds to text and binary storage loading/saving. Text storage backup filenames are built with a sized buffer and snprintf(), and storage-loaded keys/string values are rejected if they are not terminated within their configured field sizes.

The second commit is logically separable. I am happy to drop it if maintainers prefer to limit this PR to the public settings API paths only.

Scope:

  • Uses existing CONFIG_SYSTEM_SETTINGS_KEY_SIZE, CONFIG_SYSTEM_SETTINGS_VALUE_SIZE, and CONFIG_SYSTEM_SETTINGS_MAX_FILENAME limits.
  • Does not change the settings API.
  • Does not change the text or binary storage formats.
  • Does not mechanically replace every string helper; changes are limited to settings fields with known configured bounds.

Impact

Settings input and storage-loaded string fields are no longer scanned or compared beyond their configured maximum sizes.

  • New feature: NO
  • User adaptation required: NO intended user adaptation
  • Build process change: NO
  • Hardware/architecture/board change: NO
  • Documentation update required: NO
  • Security impact: YES, hardens bounded string handling in system/settings
  • Compatibility impact: NO intended compatibility impact

Testing

Host:

  • Windows with WSL Ubuntu 24.04
  • CPU: x86_64
  • Compiler: GCC 13.3.0

Checks:

  • git diff --check upstream/master..HEAD: pass
  • checkpatch.sh -c -u -m -g HEAD~2..HEAD: pass
  • rg -n "strlen\(|strcmp\(|strncpy\(|strcpy\(|strcat\(" system/settings: no matches
  • sim:nsh build with CONFIG_SYSTEM_SETTINGS=y and CONFIG_SYSTEM_SETTINGS_CACHED_SAVES disabled: pass
    • confirmed CC: settings.c
    • confirmed CC: storage_bin.c
    • confirmed CC: storage_text.c
    • result: SIM elf with dynamic libs archive in nuttx.tgz

Note: the temporary test build disables CONFIG_SYSTEM_SETTINGS_CACHED_SAVES because the base sim:nsh settings configuration otherwise needs SIGEV_THREAD support, which is outside the scope of this string-handling PR.

Use strnlen() for public key, value, and storage path length checks so user-provided settings strings are validated against the configured maximum sizes before they are scanned.

Use bounded key comparisons and strlcpy() for fixed-size settings fields. This addresses part of apache#3109 without changing the settings API or storage formats.

Signed-off-by: Nightt <87569709+nightt5879@users.noreply.github.com>
Use configured key, value, and filename limits while loading and saving settings storage data.

The text backend now builds backup filenames with a sized buffer and bounded formatting, and both text and binary loading reject keys or string values that are not terminated within their configured field sizes. This completes apache#3109 without changing the storage formats.

Signed-off-by: Nightt <87569709+nightt5879@users.noreply.github.com>
@nightt5879 nightt5879 marked this pull request as ready for review May 27, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Use safer string manipulation functions in system/settings

2 participants