Fix crash when the configured cache home contains no path components - #213
Open
djw8605 wants to merge 2 commits into
Open
Fix crash when the configured cache home contains no path components#213djw8605 wants to merge 2 commits into
djw8605 wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Configuration::path_split()accessedpath_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:Because
load_config_from_environment()runs from a__attribute__((constructor)), settingSCITOKEN_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
path_split().set_cache_home()with a proper error message instead of silently storing an empty cache home.Testing
KeycacheTest.SetCacheHomeAllSlashesTestcovers/,//,///(crashed before, clean error after).rv=-1with the error message.ctestunit, env_config, and monitoring suites pass.🤖 Generated with Claude Code