Skip to content

Commit

Permalink
Do not crash when there are no active LSM modules
Browse files Browse the repository at this point in the history
Reading ".target.string" could return nil instead of "" when read path
does not exist.
  • Loading branch information
dgdavid committed Aug 23, 2022
1 parent 6140fdc commit 865895d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/y2security/lsm/config.rb
Expand Up @@ -126,7 +126,7 @@ def read
def active
return [] unless Yast::Stage.normal

modules = Yast::SCR.Read(Yast.path(".target.string"), RUNNING_PATH)
modules = Yast::SCR.Read(Yast.path(".target.string"), RUNNING_PATH).to_s
modules.split(",").each_with_object([]) do |name, result|
supported_module = supported.find { |m| m.id.to_s == name }
result << supported_module if supported_module
Expand Down
8 changes: 8 additions & 0 deletions test/y2security/lsm/config_test.rb
Expand Up @@ -66,6 +66,14 @@
expect(active.first.id).to eql(:selinux)
end

context "when there are no active LSM modules" do
let(:active_modules) { nil }

it "returns an empty array" do
expect(subject.active).to eq([])
end
end

context "when no supported LSM is active" do
let(:active_modules) { "lockdown,capabilities,tomoyo" }

Expand Down

0 comments on commit 865895d

Please sign in to comment.