Skip to content

Commit 3b73e3b

Browse files
CopilotJohnAmadis
andcommitted
Fix incorrect directory iteration in configure_drivers - use absolute paths
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
1 parent 36d8197 commit 3b73e3b

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

src/dmdevfs.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -799,20 +799,40 @@ static int configure_drivers(dmfsi_context_t ctx, const char* driver_name, const
799799
void* dir = Dmod_OpenDir(config_path);
800800
if (dir == NULL)
801801
{
802-
DMOD_LOG_ERROR("Failed to open config directory: %s\n", ctx->config_path);
802+
DMOD_LOG_ERROR("Failed to open config directory: %s\n", config_path);
803803
return DMFSI_ERR_NOT_FOUND;
804804
}
805805

806806
const char* entry;
807807
while ((entry = Dmod_ReadDir(dir)) != NULL)
808808
{
809-
if (is_file(entry))
809+
// Construct full path for the entry
810+
char full_path[MAX_PATH_LENGTH];
811+
size_t config_path_len = strlen(config_path);
812+
size_t entry_len = strlen(entry);
813+
814+
// Check if we need a separator
815+
bool needs_separator = (config_path_len > 0 && config_path[config_path_len - 1] != '/');
816+
size_t required_len = config_path_len + (needs_separator ? 1 : 0) + entry_len + 1;
817+
818+
if (required_len > MAX_PATH_LENGTH)
819+
{
820+
DMOD_LOG_ERROR("Path too long: %s/%s\n", config_path, entry);
821+
continue;
822+
}
823+
824+
Dmod_SnPrintf(full_path, sizeof(full_path), "%s%s%s",
825+
config_path,
826+
needs_separator ? "/" : "",
827+
entry);
828+
829+
if (is_file(full_path))
810830
{
811831
char module_name[DMOD_MAX_MODULE_NAME_LENGTH];
812-
dmini_context_t config_ctx = read_driver_for_config(entry, module_name, sizeof(module_name), driver_name);
832+
dmini_context_t config_ctx = read_driver_for_config(full_path, module_name, sizeof(module_name), driver_name);
813833
if (config_ctx == NULL)
814834
{
815-
DMOD_LOG_ERROR("Failed to read driver for config: %s\n", entry);
835+
DMOD_LOG_ERROR("Failed to read driver for config: %s\n", full_path);
816836
continue;
817837
}
818838

@@ -835,10 +855,10 @@ static int configure_drivers(dmfsi_context_t ctx, const char* driver_name, const
835855
// read driver name from directory name
836856
char module_name[DMOD_MAX_MODULE_NAME_LENGTH];
837857
read_base_name(entry, module_name, sizeof(module_name));
838-
int res = configure_drivers(ctx, driver_name, entry);
858+
int res = configure_drivers(ctx, driver_name, full_path);
839859
if (res != DMFSI_OK)
840860
{
841-
DMOD_LOG_ERROR("Failed to configure drivers in directory: %s\n", entry);
861+
DMOD_LOG_ERROR("Failed to configure drivers in directory: %s\n", full_path);
842862
}
843863
}
844864
}

0 commit comments

Comments
 (0)