chef / chef/mixlib-shellout

shell_out without a bang can fail if there's no shell metacharacters and the file does not exist

Open
#162 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Bug
Dominant language
Ruby
Stars
133
Forks
73
Avg merge
8h 20m
Merged PRs (30d)
2

Description

[1] pry(main)> require 'chef/mixin/shell_out'
=> true
[2] pry(main)> include Chef::Mixin::ShellOut
=> Object
[3] pry(main)> shell_out("lskdjflskj 'foo'")
=> <Mixlib::ShellOut#70318079326640: command: 'lskdjflskj 'foo'' process_status: #<Process::Status: pid 4874 exit 127> stdout: '' stderr: 'sh: lskdjflskj: command not found' child_pid: 4874 environment: {"LC_ALL"=>"en_US.UTF-8", "LANGUAGE"=>"en_US.UTF-8", "LANG"=>"en_US.UTF-8", "PATH"=>"/Users/lamont/.rvm/gems/ruby-2.5.1/bin:/Users/lamont/.rvm/gems/ruby-2.5.1@global/bin:/Users/lamont/.rvm/rubies/ruby-2.5.1/bin:/opt/chefdk/bin:/Users/lamont/.chefdk/gem/ruby/2.5.0/bin:/opt/chefdk/embedded/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/lamont/bin:/usr/local/sbin:/opt/chefdk/gitbin:/Users/lamont/.rvm/bin"} timeout: 600 user:  group:  working_dir:  >
[4] pry(main)> shell_out("lskdjflskj")
Errno::ENOENT: No such file or directory - lskdjflskj
from /Users/lamont/.rvm/gems/ruby-2.5.1/gems/mixlib-shellout-2.3.2/lib/mixlib/shellout/unix.rb:340:in `exec'

The second case should probably catch Errno::ENOENT and remap it onto the same error message you get from calling error!:

[5] pry(main)> shell_out("lskdjflskj 'foo'").error!
Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '127'
---- Begin output of lskdjflskj 'foo' ----
STDOUT:
STDERR: sh: lskdjflskj: command not found
---- End output of lskdjflskj 'foo' ----
Ran lskdjflskj 'foo' returned 127
from /Users/lamont/.rvm/gems/ruby-2.5.1/gems/mixlib-shellout-2.3.2/lib/mixlib/shellout.rb:293:in `invalid!'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the exec call in lib/mixlib/shellout/unix.rb:340 and the error handling shown in lib/mixlib/shellout.rb:293. Compare shell_out("lskdjflskj") with shell_out("lskdjflskj 'foo'").error!. Done means the missing executable produces the same ShellCommandFailed-style message rather than exposing Errno::ENOENT.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.