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
Test that overly long entries in DL_LOAD_PATH don't result in segfault
  • Loading branch information
martinholters committed Jun 26, 2020
commit 2e4e0f932b05ce2571619dd57622744e0010ab70
22 changes: 21 additions & 1 deletion stdlib/Libdl/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,16 @@ let dl = C_NULL
@test_skip !Libdl.dlclose(dl) # Syscall doesn't fail on Win32
end

# test @executable_path expansion
# test DL_LOAD_PATH handling and @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 an absurdly long entry to the load path to verify it doesn't lead to a buffer overflow
push!(Base.DL_LOAD_PATH, joinpath(dir, join(rand('a':'z', 10000))))

# 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)))

Expand All @@ -243,6 +246,23 @@ mktempdir() do dir
fptr = Libdl.dlsym_e(dl, :foo)
@test fptr == C_NULL
end

# Now use the absolute path
empty!(Base.DL_LOAD_PATH)
push!(Base.DL_LOAD_PATH, joinpath(dir, join(rand('a':'z', 10000))))
push!(Base.DL_LOAD_PATH, dir)

# 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