From: usa@... Date: 2016-06-08T04:53:21+00:00 Subject: [ruby-core:75883] [Ruby trunk Bug#12355] [PATCH] exec, system, and spawn fail when Array#to_hash is defined and their first argument is an Array Issue #12355 has been updated by Usaku NAKAMURA. Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: WONTFIX, 2.2: REQUIRED, 2.3: REQUIRED ---------------------------------------- Bug #12355: [PATCH] exec, system, and spawn fail when Array#to_hash is defined and their first argument is an Array https://bugs.ruby-lang.org/issues/12355#change-59060 * Author: Dennis Taylor * Status: Closed * Priority: Normal * Assignee: * ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] * Backport: 2.1: WONTFIX, 2.2: REQUIRED, 2.3: REQUIRED ---------------------------------------- When any gem which adds a to_hash method to Array is loaded (extlib, dropbox, others), Kernel.exec, Kernel.system, and Kernel.spawn will fail when you specify the program name with an array. Behold: ~~~ irb(main):001:0> ex = "/usr/local/bin/cowsay"; Kernel.exec([ex, ex], "-t", "Hello world") Errno::ENOENT: No such file or directory - -t from (irb):1:in `exec' ~~~ You can duplicate it yourself in irb without loading any gems by just defining an Array#to_hash method of your own: ~~~ irb(main):001:0> class Array; def to_hash; raise "HONK"; end; end; ex = "/usr/local/bin/cowsay"; Kernel.exec([ex, ex], "-t", "Hello world") RuntimeError: HONK from (irb):1:in `to_hash' from (irb):1:in `exec' ~~~ (Let's leave aside the issue of whether it's a good idea or not to add a to_hash method to Array in the first place; the basic language functionality should still be robust in the presence of people doing silly things.) The problem is that, because it thinks that the first parameter is something hash-like, it assumes that it's the "env" parameter, and goes on to use the first argument to the program ("-t") as the program name. I've attached a one-line patch to process.c to fix the argument parsing; it'll ensure that the first argument is not an array before trying to convert it to a hash. Output with the patch: ~~~ irb(main):001:0> class Array; def to_hash; raise "HONK"; end; end; ex = "/usr/local/bin/cowsay"; Kernel.exec([ex, ex], "-t", "Hello world") _____________ < Hello world > ------------- \ ^__^ \ (--)\_______ (__)\ )\/\ ||----w | || || ~~~ ---Files-------------------------------- process-to-hash.patch (414 Bytes) -- https://bugs.ruby-lang.org/ Unsubscribe: