Skip to content

Commit e986983

Browse files
authored
do not bail when finding directories with matching name in dlload (#51295)
1 parent c841b5f commit e986983

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/dlload.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,11 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags,
367367
}
368368
#endif
369369
// bail out and show the error if file actually exists
370-
if (jl_stat(path.buf, (char*)&stbuf) == 0)
371-
goto notfound;
370+
if (jl_stat(path.buf, (char *)&stbuf) == 0) {
371+
if (!S_ISDIR(stbuf.st_mode)) {
372+
goto notfound;
373+
}
374+
}
372375
}
373376
}
374377
}
@@ -390,8 +393,11 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags,
390393
break; // LoadLibrary already tested the rest
391394
#else
392395
// bail out and show the error if file actually exists
393-
if (jl_stat(path.buf, (char*)&stbuf) == 0)
394-
break;
396+
if (jl_stat(path.buf, (char *)&stbuf) == 0) {
397+
if (!S_ISDIR(stbuf.st_mode)) {
398+
break;
399+
}
400+
}
395401
#endif
396402
}
397403

test/ccall.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,23 @@ end
20032003
end
20042004
end
20052005

2006+
# issue #51293: Ensure we can load libraries even when a directory with the same name exists
2007+
@testset "dlload with directory collision" begin
2008+
mktempdir() do dir
2009+
# Create a subdirectory with the same name as our test library
2010+
libdir = joinpath(dir, "libccalltest")
2011+
mkdir(libdir)
2012+
2013+
# Try to load libccalltest from within this directory
2014+
cd(dir) do
2015+
# This should successfully load the library from DL_LOAD_PATH, not fail due to the directory
2016+
hdl = Libdl.dlopen(libccalltest)
2017+
@test hdl != C_NULL
2018+
Libdl.dlclose(hdl)
2019+
end
2020+
end
2021+
end
2022+
20062023
module Test57749
20072024
using Test, Zstd_jll
20082025
const prefix = "Zstd version: "

0 commit comments

Comments
 (0)