We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2062 - SDL_GetPrefPath() makes the assumption that $HOME or $XDG_DATA_HOME end in '/'
Summary: SDL_GetPrefPath() makes the assumption that $HOME or $XDG_DATA_HOME end in '/'
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.1
Hardware: All Linux
: P2 major
Assignee: Edward Rudd
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-24 12:11 UTC by neoaggelos
Modified: 2013-08-24 13:50 UTC (History)
1 user (show)

See Also:


Attachments
Patch (1.04 KB, patch)
2013-08-24 12:11 UTC, neoaggelos
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description neoaggelos 2013-08-24 12:11:00 UTC
Created attachment 1305 [details]
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.
Comment 1 Edward Rudd 2013-08-24 13:00:05 UTC
I would actually say it's the case for MOST systems that those variables do not have a trailing "/"..
Comment 2 Edward Rudd 2013-08-24 13:08:35 UTC
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
Comment 3 neoaggelos 2013-08-24 13:50:39 UTC
(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!