Project

General

Profile

Actions

Bug #7879

closed

File.readable? fails when ruby runs as root

Added by balbi (Feliple Balbi) about 11 years ago. Updated about 11 years ago.

Status:
Rejected
Target version:
ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Backport:
[ruby-core:52495]

Description

I have the following script to find sysfs (linux) files which are readable but throw an exception when read:

Dir.glob("/sys/**/*").each do |file|
next if File.directory?(file)

    if File.world_writable?(file)
            puts "#{file} is world-writable"
    end

    if File.readable?(file)
            begin
                    File.open(file) { |f|
                            result = f.readline
                    }
            rescue EOFError
                    nil
            rescue => e
                    puts e.message
            end
    end

end

If I run as a normal user, it works just fine, but when I run as root, even for files which are write only (chmod 200), File.readable?(f) will return true which makes my script fail. I have also tried File.readable_real? but it has the same outcome.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0