After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 64219 - g_get_home_dir() relies on the env variable HOME by default
g_get_home_dir() relies on the env variable HOME by default
Status: RESOLVED DUPLICATE of bug 2311
Product: glib
Classification: Platform
Component: general
1.2.x
Other other
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2001-11-10 09:09 UTC by Andres Salomon
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Andres Salomon 2001-11-10 09:09:12 UTC
g_get_home_dir() (in gutils.c, which calls g_get_any_init()) gets the
user's home directory by calling getenv("HOME").  If that fails, it uses
getpwuid() to get the user's home directory.  These (imo) are reversed;
$HOME should only be relied upon if the user's home directory cannot be
figured out via getpwuid().  There's nothing keeping $HOME consistent w/
the current user's uid.  For a perfect example of subtle bugs that can
arise because of this:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=116898&repeatmerged=yes

As you can see, sudo doesn't overwrite $HOME, so g_get_home_dir() gets the
original user's home directory, instead of root's homedir (or whatever the
user sudo runs the program as).  The same is true of setuid root (or any
user) binaries.  

Note that this is tested on glib1.2.10, but it appears that glib1.3.4 has
the same behavior.  Whether getpwuid() should be using getuid() or
geteuid() is another question (currently it uses getuid(). which means
setuid binaries will potentially write to the original user's homedir, with
the permissions/ownership of the setuid binary's user).
Comment 1 Owen Taylor 2001-11-13 17:49:13 UTC

*** This bug has been marked as a duplicate of 2311 ***