GNOME Bugzilla – Bug 646950
XDG dirs cannot be relative paths
Last modified: 2018-05-24 13:01:58 UTC
Created attachment 185352 [details] backtrace of XDG_CACHE_HOME=tmp totem I was using XDG_CACHE_HOME=tmp (and the other related variables set identically) and totem unexpectedly crashed when starting to play a file. I'm using totem 2.30.2 (from debian). I have looked at current git and I think the crash reason is on this line: http://git.gnome.org/browse/totem/tree/src/totem-uri.c#n432 where g_filename_to_uri is called on the relative path fake_filename that is constructed just above the relevant line. I haven't actually tried to modify this spot. Totem survives relative paths in the other variables (XDG_DATA_HOME, XDG_CONFIG_HOME) just fine. Backtrace is attached.
We won't crash anymore, in gnome-3-0 and master, we'll just warn gently. I would expect glib to return an absolute path for g_get_user_cache_dir(). The XDG Base spec doesn't mention whether relative paths are alright: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html commit e72ced40b1d90fa9481b8c0ab7dde10f4a961803 Author: Bastien Nocera <hadess@hadess.net> Date: Thu Apr 7 01:07:44 2011 +0100 main: Stop crash when XDG_CACHE_HOME is relative Don't crash but error when a relative path is given. https://bugzilla.gnome.org/show_bug.cgi?id=646950
We should update the spec to make this clear and glib should ignore env vars set to relative paths and spit out a warning.
Bastien, I don't think your patch actually fixes this crash. Of course, this is only my suspicion from reading it so take the claim with a grain of salt. The change I see in master adds an assertion that only guards against a NULL uri but it's the played video file uri it is checking, unrelated to the cache home variable. The spec not allowing relative directories sounds reasonable, it breaks anyway as soon programs change directory.
Take it with a grain of salt :-) because I'm wrong.
glib should warn, and set to defaults any of the XDG dirs that are relative, instead of absolute paths.
Created attachment 195567 [details] [review] relative XDG dir warning and set to default GLib will warn and set to defaults any of the follwing XDG dirs that are relative, instead of absolute paths. XDG_CACHE_HOME, XDG_CONFIG_HOME, XDG_DATA_HOME, XDG_RUNTIME_DIR
Make sure to use g_path_is_absolute() to get cross platform support right.
Created attachment 195599 [details] [review] relative XDG dir warning and set to default New patch with formatting fixed and using g_path_is_absolute.
(In reply to comment #7) > Make sure to use g_path_is_absolute() to get cross platform support right. for *XDG* directories?
Review of attachment 195599 [details] [review]: This needs some unit tests. ::: glib/gutils.c @@ +2258,3 @@ + data_dir = NULL; + g_warning ("XDG_DATA_HOME is set to relative path, setting it to default"); + } Please factor this block out into a utility function. @@ +2448,3 @@ { runtime_dir = g_strdup (getenv ("XDG_RUNTIME_DIR")); + Spurious whitespace change.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/403.