FakeShellOut uses OpenStruct without requiring ostruct — NameError on the transport (target-mode) path
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 90/100
Direzione di ricerca
Inizia in lib/mixlib/shellout/helper.rb, in FakeShellOut#initialize intorno alla riga 219, quindi esegui la riproduzione in Ruby dell’issue con e senza -rostruct. Verifica che la costruzione di FakeShellOut non generi più NameError e che status.success? restituisca ancora true senza precaricare ostruct.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
Mixlib::ShellOut::Helper::FakeShellOut#initialize calls OpenStruct.new (lib/mixlib/shellout/helper.rb:219 on main), but no file in the gem requires ostruct. On Ruby 3.x, OpenStruct isn't loaded unless something else in the process happens to require it, so constructing a FakeShellOut raises:
lib/mixlib/shellout/helper.rb:219:in `initialize': uninitialized constant Mixlib::ShellOut::Helper::FakeShellOut::OpenStruct (NameError)
FakeShellOut is used only on the transport path of __shell_out_command (when __transport_connection is set). That's Ohai / Chef target mode over a Train transport. Local shell_out never reaches it, which is presumably why it has gone unnoticed.
Impact
Running Ohai 19.1.40 in target mode (ohai --target <uri>) against a remote Linux host, every plugin that shells out throws this NameError. Ohai catches it and logs it only at trace level (Plugin Hostname threw #<NameError: ...>), so the run exits 0 and the attributes are simply missing: hostname, machinename, ipaddress, macaddress, network.interfaces, hostnamectl. The remote host returned correct output for every underlying command over the same transport.
With ostruct preloaded (RUBYOPT=-rostruct), the same target-mode run collects all of those attributes.
Reproduction
No transport or remote host needed:
require "mixlib/shellout/helper"
res = Struct.new(:stdout, :stderr, :exit_status).new("out", "", 0)
so = Mixlib::ShellOut::Helper::FakeShellOut.new(["true"], {}, res)
puts so.status.success?
| Command | Result |
|---|---|
ruby repro.rb |
NameError: uninitialized constant Mixlib::ShellOut::Helper::FakeShellOut::OpenStruct |
ruby -rostruct repro.rb |
true |
Observed with Ruby 3.1.6 and mixlib-shellout 3.3.6. The require list and the OpenStruct.new call are unchanged on main (latest tag v3.4.14): helper.rb requires only ../shellout, chef-utils, chef-utils/dsl/default_paths and chef-utils/internal, and no other file under lib/ references ostruct.
Suggested fix
Add require "ostruct" unless defined?(OpenStruct) to lib/mixlib/shellout/helper.rb. Alternatively, drop OpenStruct for a small Struct, since only success? is read.
- Lingua principale
- Ruby
- Stelle
- 133
- Fork
- 73
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di chef/mixlib-shellout
-
cgroup related tests failApertaStatus: Untriaged Type: Bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
chef/mixlib-shellout#278 ·
-
Status: Untriaged Type: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
chef/mixlib-shellout#257 ·
-
Status: Untriaged
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
chef/mixlib-shellout#245 · 2 commenti ·
-
Status: Untriaged Type: Bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 20/100
chef/mixlib-shellout#237 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
chef/mixlib-shellout#201 · 2 commenti ·
Tutte le issue di chef/mixlib-shellout
Issue simili
-
security
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
OSCON 2016Apertacontent
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
rubyevents/rubyevents#2148 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
we-promise/sure#3838 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Mend: dependency security vulnerability
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ManageIQ/manageiq-ui-classic#10341 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
rubocop/ruby-style-guide#984 ·