From 4910498820a9f6399857a6f0d757bbf287116801 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sat, 16 May 2026 00:48:00 -0400
Subject: [PATCH] android: EnumerateDirectory and GetPathInfo should fail for a
path of "".
Otherwise, this will get appended to the internal storage path, etc, making a
real directory when it shouldn't.
Reference Issue #15587.
---
src/filesystem/posix/SDL_sysfsops.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/filesystem/posix/SDL_sysfsops.c b/src/filesystem/posix/SDL_sysfsops.c
index 35ee29e246842..41dbf63344583 100644
--- a/src/filesystem/posix/SDL_sysfsops.c
+++ b/src/filesystem/posix/SDL_sysfsops.c
@@ -45,7 +45,9 @@ bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback
char *apath = NULL; // absolute path (for Android, iOS, etc). Overrides `path`.
#if defined(SDL_PLATFORM_ANDROID) || defined(SDL_PLATFORM_IOS)
- if (*path != '/') {
+ if (*path == '\0') {
+ return SDL_SetError("No such file or directory");
+ } else if (*path != '/') {
#ifdef SDL_PLATFORM_ANDROID
if (SDL_strncmp(path, "assets://", 9) == 0) {
char *pathwithsep = NULL;
@@ -348,7 +350,9 @@ bool SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info)
int rc;
#ifdef SDL_PLATFORM_ANDROID
- if (*path == '/') {
+ if (*path == '\0') {
+ return SDL_SetError("No such file or directory");
+ } else if (*path == '/') {
rc = stat(path, &statbuf);
} else if (SDL_strncmp(path, "assets://", 9) == 0) {
return Android_JNI_GetAssetPathInfo(path, info);