Remove TactilityC and Firmware subprojects (#638)
- Removed TactilityC, moved its symbols to existing modules and several new ones (pthread-module, c-symbols-module, cpp-symbols-module, posix-symbols-module, freertos-module). - Removed Firmware subproject and moved main() into Tactility subproject. - Strengthened application archive, path, version, stack-size, and device validation. - Moved symbol resolution for elf_loader to app-esp32-module. - Improved `struct Module` declarations and made module and symbol definitions in modules more consistent. - Removed old http download code from Tactility subproject. - Rename app-module's source files for consistency. - Add missing pthread symbols. - Kernel module symbols are now resolvable on all platforms.
This commit is contained in:
committed by
GitHub
parent
d3556fb536
commit
19b11eb9a8
@@ -37,6 +37,28 @@ std::string last_path_segment(const std::string& path) {
|
||||
return index == std::string::npos ? path : path.substr(index + 1);
|
||||
}
|
||||
|
||||
// Rejects absolute paths and ".." components, so a crafted tar entry can't extract outside destination_path (CWE-22).
|
||||
bool is_tar_entry_path_safe(const std::string& path) {
|
||||
if (path.empty() || path.front() == '/') {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t start = 0;
|
||||
while (start <= path.size()) {
|
||||
size_t slash = path.find('/', start);
|
||||
size_t length = (slash == std::string::npos ? path.size() : slash) - start;
|
||||
if (path.compare(start, length, "..") == 0) {
|
||||
return false;
|
||||
}
|
||||
if (slash == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
start = slash + 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// mkdir -p.
|
||||
bool ensure_directory(const std::string& path) {
|
||||
if (path.empty() || app_fs_is_directory(path)) {
|
||||
@@ -80,8 +102,9 @@ bool get_app_install_directory(std::string& out_path) {
|
||||
|
||||
bool untar_file(minitar* archive, const minitar_entry* entry, const std::string& destination_path) {
|
||||
auto absolute_path = destination_path + "/" + entry->metadata.path;
|
||||
if (!ensure_directory_recursive(destination_path)) {
|
||||
LOG_E(TAG, "Can't find or create directory %s", destination_path.c_str());
|
||||
auto parent_path = absolute_path.substr(0, absolute_path.find_last_of('/'));
|
||||
if (!ensure_directory_recursive(parent_path)) {
|
||||
LOG_E(TAG, "Can't find or create directory %s", parent_path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -111,6 +134,11 @@ bool untar(const std::string& tar_path, const std::string& destination_path) {
|
||||
minitar_entry entry {};
|
||||
while (minitar_read_entry(&archive, &entry) == 0) {
|
||||
LOG_I(TAG, "Extracting %s", entry.metadata.path);
|
||||
if (!is_tar_entry_path_safe(entry.metadata.path)) {
|
||||
LOG_E(TAG, "Rejecting unsafe tar entry path: %s", entry.metadata.path);
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
if (entry.metadata.type == MTAR_DIRECTORY) {
|
||||
if (std::strcmp(entry.metadata.name, ".") == 0 || std::strcmp(entry.metadata.name, "..") == 0 || std::strcmp(entry.metadata.name, "/") == 0) {
|
||||
continue;
|
||||
@@ -336,7 +364,12 @@ error_t app_install(const char* source_path) {
|
||||
return ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
auto staging_path = app_parent_path + "/" + last_path_segment(source_path);
|
||||
auto source_name = last_path_segment(source_path);
|
||||
if (source_name.empty() || source_name == "." || source_name == "..") {
|
||||
LOG_E(TAG, "Invalid source path %s", source_path);
|
||||
return ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
auto staging_path = app_parent_path + "/" + source_name;
|
||||
acquire_staging_lock(staging_path);
|
||||
|
||||
delete_recursively(staging_path);
|
||||
+1
@@ -13,6 +13,7 @@ constexpr auto* TAG = "app_metadata_v1";
|
||||
|
||||
bool app_metadata_parse_v1(const std::map<std::string, std::string>& properties, AppMetadata& out_metadata) {
|
||||
// [manifest]
|
||||
LOG_W(TAG, "This manifest version is deprecated. Replace it with the newer version.");
|
||||
|
||||
std::string format_version;
|
||||
if (!app_metadata_get_value(properties, "[manifest]version", format_version)) {
|
||||
@@ -17,7 +17,7 @@ extern "C" {
|
||||
|
||||
extern ServiceManifest app_internal_loader_service_manifest;
|
||||
|
||||
const ModuleSymbol app_module_symbols[] = {
|
||||
static const ModuleSymbol SYMBOLS[] = {
|
||||
// app/event
|
||||
DEFINE_MODULE_SYMBOL(app_event_subscribe),
|
||||
DEFINE_MODULE_SYMBOL(app_event_subscribe_with_app_id),
|
||||
@@ -54,7 +54,7 @@ const ModuleSymbol app_module_symbols[] = {
|
||||
// app/scheduler
|
||||
DEFINE_MODULE_SYMBOL(app_scheduler_current_app_id),
|
||||
// terminator
|
||||
MODULE_SYMBOL_TERMINATOR
|
||||
MODULE_SYMBOL_TERMINATOR,
|
||||
};
|
||||
|
||||
static error_t start() {
|
||||
@@ -70,8 +70,8 @@ Module app_module = {
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.drivers = nullptr,
|
||||
.symbols = app_module_symbols,
|
||||
.internal = nullptr
|
||||
.symbols = SYMBOLS,
|
||||
.internal = nullptr,
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user