Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid potential buffer overflow/missing zero termination of string #36408

Merged
merged 5 commits into from
Jun 28, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Libdl]: Add @executable_path expansion test
This exercises the replacement of `DL_LOAD_PATH` entries that start
with `@executable_path`.
  • Loading branch information
staticfloat authored and martinholters committed Jun 26, 2020
commit befc4c7adfe2b00602af7863aed28262ac0a37a9
23 changes: 23 additions & 0 deletions stdlib/Libdl/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,27 @@ let dl = C_NULL
@test_skip !Libdl.dlclose(dl) # Syscall doesn't fail on Win32
end

# test @executable_path expansion
mktempdir() do dir
# Create a `libdcalltest` in a directory that is not on our load path
src_path = joinpath(private_libdir, "libccalltest.$(Libdl.dlext)")
dst_path = joinpath(dir, "libdcalltest.$(Libdl.dlext)")
cp(src_path, dst_path)

# Add this temporary directory to our load path, using `@executable_path` to do so.
push!(Base.DL_LOAD_PATH, joinpath("@executable_path", relpath(dir, Sys.BINDIR)))
martinholters marked this conversation as resolved.
Show resolved Hide resolved

# Test that we can now open that file
Libdl.dlopen("libdcalltest") do dl
fptr = Libdl.dlsym(dl, :set_verbose)
@test fptr !== nothing
@test_throws ErrorException Libdl.dlsym(dl, :foo)

fptr = Libdl.dlsym_e(dl, :set_verbose)
@test fptr != C_NULL
fptr = Libdl.dlsym_e(dl, :foo)
@test fptr == C_NULL
end
end

end