![]() |
F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
|
Utility for canonicalizing file paths and checking directory containment. More...
Enumerations | |
| enum | Status { VALID, OUTSIDE_SANDBOX, INVALID_PATH, TOO_LONG } |
Functions | |
| static bool | isValidCString (FwSizeType measuredLen, FwSizeType bufferLen) |
| static Status | buildAbsolutePath (const char *path, const char *baseDir, char *resolvedOut, FwSizeType resolvedSize) |
| static Status | resolveInPlace (char *resolvedOut) |
| Status | resolvePath (const char *path, const char *baseDir, char *resolvedOut, FwSizeType resolvedSize) |
Resolve a path by collapsing . and .. segments. More... | |
| Status | resolvePath (const Fw::ConstStringBase &path, const Fw::ConstStringBase &baseDir, Fw::StringBase &resolvedOut) |
| Resolve a path (Fw::StringBase overload) More... | |
| Status | resolveFromCwd (const char *path, char *resolvedOut, FwSizeType resolvedSize) |
| Resolve a path using CWD as the base for relative paths. More... | |
| Status | checkContainment (const char *resolvedPath, const char *allowedDirectory) |
| Check whether an already-resolved path is within an allowed directory. More... | |
Variables | |
| static constexpr FwSizeType | MAX_PATH_LENGTH = FileNameStringSize |
| Maximum supported path length for resolution buffers. More... | |
Utility for canonicalizing file paths and checking directory containment.
Provides standalone functions for resolving relative paths (collapsing . and .. segments) and verifying that a resolved path falls within an allowed directory prefix. These utilities can be used independently of SandboxedFile for any path-validation need.
Definition at line 22 of file FilePathUtils.hpp.
|
static |
Definition at line 22 of file FilePathUtils.cpp.
| Status Os::FilePathUtils::checkContainment | ( | const char * | resolvedPath, |
| const char * | allowedDirectory | ||
| ) |
Check whether an already-resolved path is within an allowed directory.
Both arguments must already be canonical absolute paths (output of resolvePath or resolveFromCwd). Use this when you have already resolved paths and want to check containment without redundant resolution.
| resolvedPath | canonical absolute path (output of resolvePath) |
| allowedDirectory | canonical allowed directory prefix (must end with /) |
Definition at line 178 of file FilePathUtils.cpp.
|
static |
Definition at line 16 of file FilePathUtils.cpp.
| Status Os::FilePathUtils::resolveFromCwd | ( | const char * | path, |
| char * | resolvedOut, | ||
| FwSizeType | resolvedSize | ||
| ) |
Resolve a path using CWD as the base for relative paths.
Convenience wrapper: relative paths are resolved against the process's current working directory; absolute paths are resolved as-is. Returns INVALID_PATH if CWD cannot be determined.
| path | input path to resolve (may be relative or absolute) |
| resolvedOut | output buffer for the resolved path |
| resolvedSize | size of the output buffer |
Definition at line 160 of file FilePathUtils.cpp.
|
static |
Definition at line 77 of file FilePathUtils.cpp.
| Status Os::FilePathUtils::resolvePath | ( | const char * | path, |
| const char * | baseDir, | ||
| char * | resolvedOut, | ||
| FwSizeType | resolvedSize | ||
| ) |
Resolve a path by collapsing . and .. segments.
Performs purely textual path resolution without filesystem access. Handles ./, ../, and redundant / separators. The result is always an absolute path; relative inputs are resolved against the provided base directory.
| path | input path to resolve (may be relative or absolute) |
| baseDir | base directory for resolving relative paths (must be absolute, null-terminated; ignored if path is absolute) |
| resolvedOut | output buffer for the resolved path |
| resolvedSize | size of the output buffer |
Definition at line 136 of file FilePathUtils.cpp.
| Status Os::FilePathUtils::resolvePath | ( | const Fw::ConstStringBase & | path, |
| const Fw::ConstStringBase & | baseDir, | ||
| Fw::StringBase & | resolvedOut | ||
| ) |
Resolve a path (Fw::StringBase overload)
| path | input path string |
| baseDir | base directory for relative paths |
| resolvedOut | output string (resized to hold result) |
Definition at line 149 of file FilePathUtils.cpp.
|
static |
Maximum supported path length for resolution buffers.
Definition at line 30 of file FilePathUtils.hpp.