From aefa6547c3a616a31e311b333c385a5e8761a68a Mon Sep 17 00:00:00 2001 From: koranza <15344611+koranza@users.noreply.github.com> Date: Fri, 18 May 2018 18:25:49 -0500 Subject: check string lengths to avoid index out of bound --- lib/pure/os.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/pure/os.nim') diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 03445a035..9a1fb39d5 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -139,6 +139,7 @@ proc findExe*(exe: string, followSymlinks: bool = true; ## is added the `ExeExts <#ExeExts>`_ file extensions if it has none. ## If the system supports symlinks it also resolves them until it ## meets the actual file. This behavior can be disabled if desired. + if exe.len == 0: return template checkCurrentDir() = for ext in extensions: result = addFileExt(exe, ext) @@ -149,8 +150,9 @@ proc findExe*(exe: string, followSymlinks: bool = true; checkCurrentDir() let path = string(getEnv("PATH")) for candidate in split(path, PathSep): + if candidate.len == 0: continue when defined(windows): - var x = (if candidate[0] == '"' and candidate[^1] == '"': + var x = (if candidate.len > 2 and candidate[0] == '"' and candidate[^1] == '"': substr(candidate, 1, candidate.len-2) else: candidate) / exe else: @@ -1649,4 +1651,4 @@ proc setLastModificationTime*(file: string, t: times.Time) = var ft = t.toWinTime.toFILETIME let res = setFileTime(h, nil, nil, ft.addr) discard h.closeHandle - if res == 0'i32: raiseOSError(osLastError()) \ No newline at end of file + if res == 0'i32: raiseOSError(osLastError()) -- cgit 1.4.1-2-gfad0 From f9358e85caecb0c863a395203b759961351f9afd Mon Sep 17 00:00:00 2001 From: koranza <15344611+koranza@users.noreply.github.com> Date: Sat, 19 May 2018 14:48:19 -0500 Subject: remove unneeded check on length --- lib/pure/os.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/pure/os.nim') diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 9a1fb39d5..370420d37 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -152,7 +152,7 @@ proc findExe*(exe: string, followSymlinks: bool = true; for candidate in split(path, PathSep): if candidate.len == 0: continue when defined(windows): - var x = (if candidate.len > 2 and candidate[0] == '"' and candidate[^1] == '"': + var x = (if candidate[0] == '"' and candidate[^1] == '"': substr(candidate, 1, candidate.len-2) else: candidate) / exe else: -- cgit 1.4.1-2-gfad0