oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3.02k stars 185 forks source link

Process.euid=/Process.egid= don't accept strings #2615

Closed djberg96 closed 2 years ago

djberg96 commented 2 years ago

Ruby 3.0.2 allows a string for Process.euid=, and will (I assume) do a user lookup in that case:

# OS X
Process.euid = "test" # => can't find user for test (ArgumentError)
Process.euid = "dberger" # => "dberger"

But using Truffleruby 22.0.0.2:

Process.euid = "test" # => undefined method `to_int' for "test":String
Process.euid = "dberger" # => undefined method `to_int' for "dberger":String
chrisseaton commented 2 years ago

Seems an ancient feature.

https://github.com/ruby/ruby/commit/9bf9b3ef95e5a699b931435f482087c57439eda3

But it's never been properly specified - see here it specifies that it raises an error if not given an integer, but then also specifies that you can't set it to root, using the string, but in order to trigger an unrelated error.

https://github.com/ruby/spec/blob/a0f1a08f38d13cc6491cd1192958046bceceaf39/core/process/euid_spec.rb#L17-L45

Implementation would go here.

https://github.com/oracle/truffleruby/blob/0e730617b83d1007818ecc7452933e4a54a8832b/src/main/ruby/truffleruby/core/process.rb#L404-L430

Should be relatively easy to fix, could be a good beginner project. First thing would be specifications and then an implementation.

eregon commented 2 years ago

Converting the user name to a uid can be done with Etc.getpwnam(user).uid, which is what fileutils does: https://github.com/oracle/truffleruby/blob/0e730617b83d1007818ecc7452933e4a54a8832b/lib/mri/fileutils.rb#L1110-L1111

That means it needs require 'etc' but that seems fine since it's a rarely-used method.

djberg96 commented 2 years ago

Note that Process.egid= has the same issue.

andrykonchin commented 2 years ago

Looks like the issue is fixed and the PR is merged.