Patches: Browse | Submit New | Admin

[#23105] 'gem' method crashes if home folder doesn't exist

Date:
2008-12-04 13:49
Priority:
3
Submitted By:
Hongli Lai (hongli)
Assigned To:
Daniel Berger (djberg96)
Category:
#gem and #require methods
State:
Closed
Summary:
'gem' method crashes if home folder doesn't exist

Detailed description
If the home folder of the user that the Ruby interpreter is running as does not exist, then the 'gem' method will crash
with an Errno::ENOENT exception. The problem is in rubygems.rb, self.set_paths:

  # only create by matching user
  next if Etc.getpwuid.uid != File::Stat.new(Gem.user_home).uid

It can be fixed by replacing it with:

  # only create by matching user
  home_folder_uid = File::Stat.new(Gem.user_home).uid rescue nil
  next if Etc.getpwuid.uid != home_folder_uid


This fix is important for Phusion Passenger. Phusion Passenger supports privilege lowering: it runs a Rails application
as the owner of environment.rb. But if environment.rb is owned by root, then Phusion Passenger will run the application
as 'nobody'.
But on many systems, the user 'nobody' has the home folder '/nonexistent', which is indeed nonexistent. The 'gem' method
crashes upon trying to stat this folder.

This problem is one of the most reported Phusion Passenger issues. It only occurs in RubyGems 1.3.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2008-12-31 04:33
Sender: Daniel Berger

The patch applied from bug #23037 should fix this. Please re-open
if it does not.

Regards,

Dan

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
status_idOpen2008-12-31 04:33djberg96
resolution_idNone2008-12-31 04:33djberg96
artifact_group_idNone2008-12-31 04:33djberg96
assigned_tonone2008-12-31 04:33djberg96
close_date2008-12-31 04:332008-12-31 04:33djberg96