From 82c620304b3178748c3d8a46ffa31917651e424f Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 5 Sep 2025 23:59:05 +0200 Subject: [PATCH] Fixing bug 804. Using function get_windows_canonical_path() may neglect the ngspice file search sequence, as an absolute path is returned also for relative input paths. ngspice however searches a file not only relative to the current directory, as inforced by this function, but for example also in the directory of the previous input file. So restrict this function to paths longer than MAX_PATH, which would fail otherwise. --- src/frontend/inpcom.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index ff9bb8072..71a3bdeaf 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -9844,6 +9844,10 @@ static void inp_meas_control(struct card* card) * might need to add the prefix separately if using the result in APIs * that require it for long path support. * + * Using this function however may neglect the ngspice file search sequence, + * as an absolute path is returned also for relative paths. + * So restrict this function to paths longer than MAX_PATH. + * * @param input_path The input path string (UTF-8 encoded). Can be relative or * absolute, may contain '.' or '..'. * @return char* A newly allocated UTF-8 string containing the canonical absolute @@ -9869,6 +9873,10 @@ char* get_windows_canonical_path(const char* input_path) { inputLenMB = (int)strlen(input_path); + /* If path length is less than MAX_PATH, just copy and return path. */ + if (inputLenMB < MAX_PATH) + return copy(input_path); + if (inputLenMB == 0) { inputLenW = 1; }