Skip to content

Commit f44d1a6

Browse files
committed
fixup ispath edge cases
1 parent fed7a0a commit f44d1a6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

base/stat.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,16 @@ This is the generalization of [`isfile`](@ref), [`isdir`](@ref) etc.
327327
"""
328328
ispath(st::StatStruct) = filemode(st) & 0xf000 != 0x0000
329329
function ispath(path::String)
330-
# We use `access()` and `F_OK` to determine if a given path exists.
331-
# `F_OK` comes from `unistd.h`.
330+
if contains(path, '\0')
331+
throw(ArgumentError(string("embedded NULs are not allowed in C strings: ", repr(path), ")")))
332+
end
333+
# We use `access()` and `F_OK` to determine if a given path exists. `F_OK` comes from `unistd.h`.
332334
F_OK = 0x00
333-
return ccall(:jl_fs_access, Cint, (Ptr{UInt8}, Cint), path, F_OK) == 0
335+
r = ccall(:jl_fs_access, Cint, (Ptr{UInt8}, Cint), path, F_OK)
336+
if !(r in (0, Base.UV_ENOENT, Base.UV_ENOTDIR, Base.UV_EINVAL))
337+
uv_error(string("ispath(", repr(path), ")"), r)
338+
end
339+
return r == 0
334340
end
335341
ispath(path::AbstractString) = ispath(String(path))
336342

0 commit comments

Comments
 (0)