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

SDL_GetPrefPath() makes the assumption that $HOME or $XDG_DATA_HOME end in '/' #1046

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

SDLBugzilla commented Feb 10, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.1
Reported for operating system, platform: Linux, All

Comments on the original bug report:

On 2013-08-24 12:11:00 +0000, wrote:

Created attachment 1305
Patch

Under UNIX, SDL_GetPrefPath() will construct a path like '$HOME/.local/share/app'. The current code, however, in unix/SDL_sysfilesystem.c makes a huge (and unsafe) assumption that $HOME or $XDG_DATA_HOME contain a slash '/' in the end.

That is not the case for some systems, where $HOME might be '/home/username'. The code right now looks like this:

const char envr = SDL_getenv("XDG_DATA_HOME");
if (!envr) {
/
You end up with "$HOME/.local/share/Game Name 2" /
envr = SDL_getenv("HOME");
if (!envr) {
/
we could take heroic measures with /etc/passwd, but oh well. /
SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
return NULL;
}
} /
if */

append = ".local/share/";

But in case 'envr' does not end in '/', then we might get a path like '/home/username.local/share/appname' instead.

Attached is a patch dealing with the issue. I tested it on my machine and it works fine. Unless some serious problem pops up with this patch, I believe it should be added.

On 2013-08-24 13:00:05 +0000, Edward Rudd wrote:

I would actually say it's the case for MOST systems that those variables do not have a trailing "/"..

On 2013-08-24 13:08:35 +0000, Edward Rudd wrote:

Thanks for the report and patch. the fix up there is mostly the same except I also did a check for a "/" on XDG_DATA_HOME so we don't end up with 2 "/"'s

On 2013-08-24 13:50:39 +0000, wrote:

(In reply to Edward Rudd from comment # 2)

Thanks for the report and patch. the fix up there is mostly the same except
I also did a check for a "/" on XDG_DATA_HOME so we don't end up with 2 "/"'s

Great, thanks for fixing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant