fix: check legal_path before calling compile_object apply#398
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens filesystem sandboxing by validating object source paths with legal_path() before any virtual-object (master::compile_object()) lookup occurs, while also consolidating path handling around the misc/filepath.* helpers and adding unit tests for those helpers.
Changes:
- Enforce early
legal_path()validation and stricter mudlib-root anchoring inload_object()to prevent unsafe paths from reachingcompile_object. - Refactor path composition/normalization to use
filepath_join()/filepath_resolve_with_origin()across startup and file efuns. - Add a new GoogleTest suite for filepath helper functions and wire it into CMake.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_filepath/test_filepath.cpp | Adds unit tests for path validation, containment checks, joining, stripping, and origin-relative resolution. |
| tests/test_filepath/CMakeLists.txt | Builds and registers the new test_filepath test binary. |
| CMakeLists.txt | Adds tests/test_filepath to the test build when GTest is enabled. |
| src/stem.cpp | Switches mudlib-root path composition to filepath_join() for bounded joining + containment verification. |
| src/main.c | Resolves __LOG_DIR__ relative to config location and joins it with __DEBUG_LOG_FILE__ via filepath helpers. |
| lib/rc/rc.cpp | Resolves mudlib dir relative to the config file using filepath_resolve_with_origin() before filesystem checks. |
| lib/misc/filepath.h | Renames/reshapes the filepath helper APIs (filepath_strip, filepath_join, filepath_resolve_with_origin). |
| lib/misc/filepath.cpp | Implements the updated filepath helper APIs (strip in-place, join full path, resolve relative-to-origin). |
| src/simulate.h | Renames load_object parameter to name_or_path for clarity. |
| src/simulate.c | Canonicalizes object names, checks legal_path() before virtual object lookup, and uses verified mudlib-root joining. |
| lib/lpc/otable.h | Exposes make_otable_name() and keeps strip_name() as a legacy inline wrapper. |
| lib/lpc/otable.c | Implements make_otable_name() (strip leading slashes, collapse repeated “.c”), and updates add_slash() return type. |
| lib/lpc/compiler.c | Renames compile_file() parameter from name to source_file for clarity in tracing/logging. |
| lib/efuns/file_utils.c | Updates rename/cp helpers to use new filepath helpers and preserve basename-append behavior explicitly. |
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.
No description provided.