diff --git a/base/stat.jl b/base/stat.jl index f527664f228ad..35e02d2c373f9 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -327,10 +327,15 @@ This is the generalization of [`isfile`](@ref), [`isdir`](@ref) etc. """ ispath(st::StatStruct) = filemode(st) & 0xf000 != 0x0000 function ispath(path::String) + if contains(path, '\0') + throw(ArgumentError("embedded NULs are not allowed in C strings: \"$(repr(path))\"")) + end # We use `access()` and `F_OK` to determine if a given path exists. # `F_OK` comes from `unistd.h`. F_OK = 0x00 - return ccall(:jl_fs_access, Cint, (Ptr{UInt8}, Cint), path, F_OK) == 0 + res = ccall(:jl_fs_access, Cint, (Ptr{UInt8}, Cint), path, F_OK) + @assert res in (0, Base.UV_ENOENT) + return res == 0 end ispath(path::AbstractString) = ispath(String(path))