Skip to content

Fix crash when the configured cache home contains no path components - #213

Open
djw8605 wants to merge 2 commits into
scitokens:masterfrom
djw8605:fix/path-split-crash
Open

Fix crash when the configured cache home contains no path components#213
djw8605 wants to merge 2 commits into
scitokens:masterfrom
djw8605:fix/path-split-crash

Conversation

@djw8605

@djw8605 djw8605 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Problem

Configuration::path_split() accessed path_components[0] without checking whether the vector is empty. Any cache-home value consisting only of slashes (/, //, …) produces an empty vector, so the access is out of bounds — a reproducible SIGSEGV:

scitoken_config_set_str("keycache.cache_home", "/", &err);  // segfault

Because load_config_from_environment() runs from a __attribute__((constructor)), setting SCITOKEN_CONFIG_KEYCACHE_CACHE_HOME=/ in the environment crashes any application that links the library, at load time.

The path_components[0] == "" check was also dead code: empty components are already filtered inside the split loop, so the first element can never be empty.

Fix

  • Remove the dead (and crashing) check from path_split().
  • Reject component-less cache-home paths in set_cache_home() with a proper error message instead of silently storing an empty cache home.

Testing

  • New regression test KeycacheTest.SetCacheHomeAllSlashesTest covers /, //, /// (crashed before, clean error after).
  • Standalone repro that segfaulted before this change now returns rv=-1 with the error message.
  • ctest unit, env_config, and monitoring suites pass.

🤖 Generated with Claude Code

djw8605 and others added 2 commits July 6, 2026 12:51
Configuration::path_split() accessed path_components[0] without
checking for an empty vector.  Any all-slash cache home value ("/",
"//", ...) produced an empty vector and an out-of-bounds access,
crashing with SIGSEGV.  Because load_config_from_environment() runs
from a library constructor, setting SCITOKEN_CONFIG_KEYCACHE_CACHE_HOME=/
crashed any application linking the library at load time.

The [0] check was also dead code: empty components are already
filtered inside the split loop, so the first element can never be an
empty string.

Remove the dead check and reject component-less cache home paths in
set_cache_home() with a proper error.  Adds a regression test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@djw8605 djw8605 added the ai-gen label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant