Bug 1601934 - Trace on non existent home directory
Summary: Trace on non existent home directory
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: ruby
Version: 7.5
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: rc
: ---
Assignee: Jun Aruga
QA Contact: David Jež
URL:
Whiteboard:
Depends On:
Blocks: 1477664 1602879 1602880 1630906 1630914 1661173
TreeView+ depends on / blocked
 
Reported: 2018-07-17 13:44 UTC by Julio Entrena Perez
Modified: 2019-08-06 12:05 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: No Doc Update
Doc Text:
Clone Of:
: 1602877 1602879 1602880 (view as bug list)
Environment:
Last Closed: 2019-08-06 12:04:58 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2019:2028 None None None 2019-08-06 12:05:22 UTC

Description Julio Entrena Perez 2018-07-17 13:44:49 UTC
Description of problem:
If the home directory for the current user does not exist ruby fails to run and produces a trace after trying to concatenate the empty string for the home directory to the gam_path.

Version-Release number of selected component (if applicable):
ruby-2.0.0.648-33.el7_4

How reproducible:
Always

Steps to Reproduce:
1. Create a user with a non existent home directory

# useradd -M -d /nodir alice

2. Run ruby as the above user

# su - alice
Last login: Tue Jul 17 13:04:17 BST 2018 on pts/1
su: warning: cannot change directory to /nodir: No such file or directory

-bash-4.2$ ruby

Actual results:

-bash-4.2$ ruby
/usr/share/rubygems/rubygems/path_support.rb:68:in `path=': undefined method `+' for nil:NilClass (NoMethodError)
	from /usr/share/rubygems/rubygems/path_support.rb:30:in `initialize'
	from /usr/share/rubygems/rubygems.rb:357:in `new'
	from /usr/share/rubygems/rubygems.rb:357:in `paths'
	from /usr/share/rubygems/rubygems.rb:379:in `path'
	from /usr/share/rubygems/rubygems/specification.rb:796:in `dirs'
	from /usr/share/rubygems/rubygems/specification.rb:660:in `each_normal'
	from /usr/share/rubygems/rubygems/specification.rb:671:in `_all'
	from /usr/share/rubygems/rubygems/specification.rb:824:in `each'
	from /usr/share/rubygems/rubygems/specification.rb:866:in `find'
	from /usr/share/rubygems/rubygems/specification.rb:866:in `find_inactive_by_path'
	from /usr/share/rubygems/rubygems.rb:175:in `try_activate'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:132:in `rescue in require'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:144:in `require'
	from <internal:abrt_prelude>:2:in `<compiled>'
-bash-4.2$ 

Ruby is failing to concatenate a nil string (the non existent home directory) to the gem_path:

/usr/share/rubygems/rubygems/path_support.rb
     42   ##
     43   # Set the Gem search path (as reported by Gem.path).
     44 
     45   def path=(gpaths)
     46     # FIX: it should be [home, *path], not [*path, home]
     47 
     48     gem_path = []

     67     else
     68       gem_path = Gem.default_path + [@home]

Appending "nil" to gem_path should never happen.

Expected results:

No trace is displayed, ruby waits for input on standard input.
Possibly a check prevents appending @home to gem_path if the former is nil.

Additional info:

This is also present in current version 2.5.1p57 (2018-03-29 revision 63029) (ruby-2.5.1-93.fc28)

Comment 1 Pavel Valena 2018-07-18 14:10:26 UTC
Hello Julio,

thank you for you report. I can confirm this is an issue. The cause is however different.

/usr/share/rubygems/rubygems/path_support.rb
    67      else
    68        gem_path = Gem.default_path + [@home]
    69

Here `Gem.default_path` is `nil`, because it is overriden, based on our implementation of `operating_system.rb`.

/usr/share/rubygems/rubygems/defaults/operating_system.rb
    67      def default_path
    68        path = default_dirs.collect {|location, paths| paths[:gem_dir]}
    69        path.unshift Gem.user_dir if File.exist? Gem.user_home
    70      end

The method DOES NOT return `path` in case `Gem.user_home` is nonexistent.

It can be easily fixed by adding one line:
    67      def default_path
    68        path = default_dirs.collect {|location, paths| paths[:gem_dir]}
    69        path.unshift Gem.user_dir if File.exist? Gem.user_home
    70        path
    71      end

This unfortunately also affects all Red Hat Software Collections' Ruby packages.

Comment 3 Vít Ondruch 2018-10-24 11:53:51 UTC
https://src.fedoraproject.org/rpms/ruby/pull-request/23

This ^^ is the PR fixing the issue in Fedora.

Comment 4 Jun Aruga 2018-12-20 11:55:20 UTC
Sent PR: https://src.osci.redhat.com/rpms/ruby/pull-request/7

Comment 9 errata-xmlrpc 2019-08-06 12:04:58 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2019:2028


Note You need to log in before you can comment on or make changes to this bug.