From 827ed63eb30c84c4e095307ec6b77be422e14fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Baru=C4=8Di=C4=87?= Date: Thu, 19 May 2022 10:38:14 +0200 Subject: [PATCH] safe_realpath: fix stack overflow This commit prevents stack overflow when `safe_realpath` is called with a non-existing path that does not start with a `/`, such as "D:\ProjectA" (on a Windows machine without drive D:) "" "non-existing-path" Resolves #3085 --- src/utils.jl | 1 + test/misc.jl | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index d013dd68c3..71a05e0da4 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -58,6 +58,7 @@ set_readonly(::Nothing) = nothing # try to call realpath on as much as possible function safe_realpath(path) + isempty(path) && return path if ispath(path) try return realpath(path) diff --git a/test/misc.jl b/test/misc.jl index a2f565a0b4..557b484bd0 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -17,4 +17,12 @@ end hash(Pkg.Types.VersionSpec()) # hash isn't stable hash(Pkg.Types.PackageEntry()) # hash isn't stable because the internal `repo` field is a mutable struct end + +@testset "safe_realpath" begin + # issue #3085 + for p in ("", "some-non-existing-path") + @test p == Pkg.safe_realpath(p) + end +end + end # module