ruby-shadow icon indicating copy to clipboard operation
ruby-shadow copied to clipboard

putspent coredumps on latest Ubuntu, RPM distros

Open nyetsche opened this issue 1 year ago • 0 comments

Tested with ruby 2.5.9p229 on Rocky 8.8, and ruby 3.0.2p107 on Ubuntu 22.04 (Jammy).

root@c3d40e9bb44f:/# cat ./example.rb
#!/usr/bin/env ruby

require 'shadow'
u = Shadow::Passwd::getspnam('root')
Shadow::Passwd::putspent(u, File.open('/etc/newshadow', 'w+'))
root@c3d40e9bb44f:/# ./example.rb
./example.rb:5: [BUG] Segmentation fault at 0x0000000000000000
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [aarch64-linux-gnu]

-- Control frame information -----------------------------------------------
c:0003 p:---- s:0013 e:000012 CFUNC  :putspent
c:0002 p:0057 s:0007 E:000a78 EVAL   ./example.rb:5 [FINISH]
c:0001 p:0000 s:0003 E:000840 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
./example.rb:5:in `<main>'
./example.rb:5:in `putspent'

-- Machine register context ------------------------------------------------
 "x0: 0x0000000000000008 "x1: 0x0000000000000000 "x2: 0x000000000000000

(Similar trace from Rocky 8.8, Ruby 2.5.1).

Way back in 2013 this was fixed by a PR - https://github.com/apalmblad/ruby-shadow/pull/13 - does that need updating? I'm not a Ruby library, I only discovered this during the course of other work (in Puppet).

The fgetspent function does work, and as far as I can tell it's using the same File/stdio object.

root@c3d40e9bb44f:/# cat example.rb
#!/usr/bin/env ruby

require 'shadow'
u = Shadow::Passwd::fgetspent(File.open('/etc/shadow', 'r'))
puts(u)
root@c3d40e9bb44f:/# ./example.rb
#<struct Struct::PasswdEntry sp_namp="root", sp_pwdp="*", sp_lstchg=19532, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, pw_change=nil, sp_expire=-1, sp_flag=-1, sp_loginclass=nil>

nyetsche avatar Jul 19 '23 15:07 nyetsche