-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Milestone
Description
When calling SDL_GlobDirectory(), it pattern-matches after descending into a sub-directory to check if it is a match.
This causes the function to fail, when globbing with the pattern "*" on a directory, that has permissions, but its sub-directories don't.
This happens for example with the root directory "/".
Edit:
A different alternative would be, instead of stopping on error, to just skip a directory.
example:
#include <SDL3/SDL.h>
const char *path = "/";
const char *pattern = "*";
SDL_EnumerationResult enum_dir_func(void *userdata, const char *dirname, const char *fname)
{
SDL_Log("%s", fname);
return SDL_ENUM_CONTINUE;
}
int main(void)
{
SDL_Log("SDL_EnumerateDirectory(\"%s\")", path);
if (!SDL_EnumerateDirectory(path, enum_dir_func, NULL)) {
SDL_Log("ERROR: SDL_EnumerateDirectory() %s", SDL_GetError());
}
SDL_Log("");
SDL_Log("SDL_GlobDirectory(\"%s\",\"%s\")", path, pattern);
char **globs = SDL_GlobDirectory(path, pattern, 0, NULL);
if (!globs) {
SDL_Log("ERROR: SDL_GlobDirectory() %s", SDL_GetError());
} else {
for(char **it = globs; *it; ++it) {
SDL_Log("%s", *it);
}
}
return 0;
}output:
./a.out
SDL_EnumerateDirectory("/")
tmp
var
efi
root
bin
dev
lost+found
media
mnt
run
lib64
proc
sbin
opt
lib
srv
etc
home
sys
boot
usr
SDL_GlobDirectory("/","*")
ERROR: SDL_GlobDirectory() Can't open directory: Permission denied
output with sudo:
sudo ./a.out
SDL_EnumerateDirectory("/")
tmp
var
efi
root
bin
dev
lost+found
media
mnt
run
lib64
proc
sbin
opt
lib
srv
etc
home
sys
boot
usr
SDL_GlobDirectory("/","*")
tmp
var
efi
root
bin
dev
lost+found
media
mnt
run
lib64
proc
sbin
opt
lib
srv
etc
home
sys
boot
usr
Edit: Here is the code where it descends into a sub-directory
SDL/src/filesystem/SDL_filesystem.c
Lines 346 to 354 in 67ac0e5
| if (matched_to_dir) { | |
| SDL_PathInfo info; | |
| if (data->getpathinfo(fullpath, &info, data->fsuserdata) && (info.type == SDL_PATHTYPE_DIRECTORY)) { | |
| //SDL_Log("GlobDirectoryCallback: Descending into subdir '%s'", fname); | |
| if (!data->enumerator(fullpath, GlobDirectoryCallback, data, data->fsuserdata)) { | |
| result = SDL_ENUM_FAILURE; | |
| } | |
| } | |
| } |
Reactions are currently unavailable