From 4d9e13b290574cce5d11cb6dd83fcdde5c081354 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Thu, 7 May 2020 16:31:40 -0700 Subject: [PATCH] `download()`: Clear libpath environment variables before invoking `curl` We generally don't have a problem when invoking external executables, however occasionally we are doing something such as running `rr`, which needs `libgcc_s` from the Julia CSL distribution, and the only way to get `libgcc_s` for `rr` is to tack its location on to the end of `LD_LIBRARY_PATH`. This causes all other executables to search that directory as well, and right now, that directory is Julia's entire private libdir, which includes many things such as `libcurl.so`. This breaks a system-provided `curl`. This wil be fixed by JLL stdlib bundling, as we will have much more fine-grained control over which libraries are added to the paths for which executables, however in the meantime, an easy fix is to isolate the system `curl` from our libraries by removing the libpath environment variables before invoking it. --- base/download.jl | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/base/download.jl b/base/download.jl index 0b9c6ba519a8bf..cbf58c5bf302f5 100644 --- a/base/download.jl +++ b/base/download.jl @@ -35,9 +35,21 @@ function find_curl() end end +# Clear libpath for invoking system executables that we generally don't want to be confused +# by things like a libcurl that sits in Julia's private libdir. +function clear_libpath(f::Function) + withenv(f, + "LD_LIBRARY_PATH" => nothing, + "DYLD_FALLBACK_LIBRARY_PATH" => nothing, + "DYLD_LIBRARY_PATH" => nothing, + ) +end + function download_curl(curl_exe::AbstractString, url::AbstractString, filename::AbstractString) err = PipeBuffer() - process = run(pipeline(`$curl_exe -s -S -g -L -f -o $filename $url`, stderr=err), wait=false) + process = clear_libpath() do + run(pipeline(`$curl_exe -s -S -g -L -f -o $filename $url`, stderr=err), wait=false) + end if !success(process) error_msg = readline(err) @error "Download failed: $error_msg" @@ -64,14 +76,18 @@ function download(url::AbstractString, filename::AbstractString) return download_powershell(url, filename) elseif Sys.which("wget") !== nothing try - run(`wget -O $filename $url`) + clear_libpath() do + run(`wget -O $filename $url`) + end catch rm(filename, force=true) # wget always creates a file rethrow() end elseif Sys.which("busybox") !== nothing try - run(`busybox wget -O $filename $url`) + clear_libpath() do + run(`busybox wget -O $filename $url`) + end catch rm(filename, force=true) # wget always creates a file rethrow()