Bug #8918

Shell::CommandProcessor::find_system_command

Added by James Cox over 1 year ago. Updated over 1 year ago.

[ruby-core:57235]
Status:Closed
Priority:Normal
Assignee:-
ruby -v:ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux] Backport:1.9.3: UNKNOWN, 2.0.0: UNKNOWN

Description

I inherited some code which is using Shell::CommandProcessor::find_system_command to verify that the specified command actually exist, and get the full path to it. I pulled this small chunk out for testing:

require 'shell'
shell = Shell.new
puts shell.command_processor.find_system_command("perl")

The issues was triggered by someone running the rake system with a directory named "perl" on their path before the path which would find the actual perl command. To reproduce, I created a directory named "perl" in "~/bin". The user who hit the issue just has a collection of perl scripts in this directory. When "~/bin" is listed in the path before the real perl executable, the find_system_command function will return the directory named "perl" rather than the path to the perl command. This needs to have an added check to verify that the path found is an executable file, rather than a directory, and continue to search the path if directory.

I don't know if Shell::CommandProcessor::find_system_command is the best method for accomplishing this task since this seems to be listed as a private function on ruby-doc.org. I will probably need to just work around it for now, so I don't know if I will be checking back in on the bug. This seems to occur in both 1.9.1 (default on my system) and in the 2.0.0p247 I downloaded for evaluation recently.

$ ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

Associated revisions

Revision 42961
Added by Nobuyoshi Nakada over 1 year ago

command-processor.rb: return executable file only

  • lib/shell/command-processor.rb (Shell::CommandProcessor#find_system_command): return executable file only, should ignore directories and unexecutable files. [Bug #8918]

Revision 42961
Added by Nobuyoshi Nakada over 1 year ago

command-processor.rb: return executable file only

  • lib/shell/command-processor.rb (Shell::CommandProcessor#find_system_command): return executable file only, should ignore directories and unexecutable files. [Bug #8918]

Revision 42962
Added by Nobuyoshi Nakada over 1 year ago

command-processor.rb: return executable file only

  • lib/shell/command-processor.rb (Shell::CommandProcessor#find_system_command): return executable file only, should ignore directories and unexecutable files. [Bug #8918]

Revision 42962
Added by Nobuyoshi Nakada over 1 year ago

command-processor.rb: return executable file only

  • lib/shell/command-processor.rb (Shell::CommandProcessor#find_system_command): return executable file only, should ignore directories and unexecutable files. [Bug #8918]

Revision 43041
Added by Nobuyoshi Nakada over 1 year ago

test_command_processor.rb: fix for mswin/mingw and test for directory

  • test/shell/test_command_processor.rb (test_system_external): fix for
    mswin and mingw. one of EXECUTABLE_EXTS is needed but shell.rb does
    not support it.

  • test/shell/test_command_processor.rb (test_system_directory): test
    not to find directory. [Bug #8918]

Revision 43041
Added by Nobuyoshi Nakada over 1 year ago

test_command_processor.rb: fix for mswin/mingw and test for directory

  • test/shell/test_command_processor.rb (test_system_external): fix for
    mswin and mingw. one of EXECUTABLE_EXTS is needed but shell.rb does
    not support it.

  • test/shell/test_command_processor.rb (test_system_directory): test
    not to find directory. [Bug #8918]

History

#1 Updated by Nobuyoshi Nakada over 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42961.
James, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


command-processor.rb: return executable file only

  • lib/shell/command-processor.rb (Shell::CommandProcessor#find_system_command): return executable file only, should ignore directories and unexecutable files. [Bug #8918]

Also available in: Atom PDF