helper: configuration: check for empty search dirs

The function find_file() is supposed to be called when the search
dirs in 'script_search_dirs' has already been populated.

This is not the case when the command 'ocd_find' is used in one of
the embedded scripts 'startup.tcl'. It then triggers SIGSEGV.

Check for 'script_search_dirs' and eventually skip searching in
the dirs.

Change-Id: I9e75a8739c94de72041fb64487910d60dffcb2bd
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8931
Tested-by: jenkins
This commit is contained in:
Antonio Borneo
2025-05-22 02:02:19 +02:00
parent 3fbca95ae1
commit 40e6c98dfc

View File

@@ -71,17 +71,18 @@ char *find_file(const char *file)
full_path = alloc_printf("%s", file); full_path = alloc_printf("%s", file);
fp = fopen(full_path, mode); fp = fopen(full_path, mode);
while (!fp) { if (script_search_dirs)
free(full_path); while (!fp) {
full_path = NULL; free(full_path);
dir = *search_dirs++; full_path = NULL;
dir = *search_dirs++;
if (!dir) if (!dir)
break; break;
full_path = alloc_printf("%s/%s", dir, file); full_path = alloc_printf("%s/%s", dir, file);
fp = fopen(full_path, mode); fp = fopen(full_path, mode);
} }
if (fp) { if (fp) {
fclose(fp); fclose(fp);