Skip to content

Commit

Permalink
Merge pull request #704 from atambo/kernel_exec_error_on_null_byte
Browse files Browse the repository at this point in the history
Kernel.exec should raise an ArgumentError if the command includes a null byte
  • Loading branch information
headius committed May 4, 2013
2 parents 48dd511 + acaec7a commit d90f2db
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 0 additions & 2 deletions spec/tags/1.8/ruby/core/kernel/exec_tags.txt
@@ -1,10 +1,8 @@
fails:Kernel#exec raises an ArgumentError if the command includes a null byte
fails:Kernel#exec raises Errno::EACCES when passed a directory
fails:Kernel#exec with a single argument subjects the specified command to shell expansion
fails:Kernel#exec with a command array uses the first element as the command name and the second as the argv[0] value
fails:Kernel#exec with a command array coerces the argument using to_ary
fails:Kernel#exec with a command array raises Argument error if the Array does not have exactly two elements
fails:Kernel.exec raises an ArgumentError if the command includes a null byte
fails:Kernel.exec raises Errno::EACCES when passed a directory
fails:Kernel.exec with a single argument subjects the specified command to shell expansion
fails:Kernel.exec with a command array uses the first element as the command name and the second as the argv[0] value
Expand Down
2 changes: 0 additions & 2 deletions spec/tags/1.9/ruby/core/kernel/exec_tags.txt
@@ -1,11 +1,9 @@
fails:Kernel#exec raises an ArgumentError if the command includes a null byte
fails:Kernel#exec raises Errno::EACCES when passed a directory
fails:Kernel#exec unsets other environment variables when given a true :unsetenv_others option
fails:Kernel#exec sets the current directory when given the :chdir option
fails:Kernel#exec with a single argument subjects the specified command to shell expansion
fails:Kernel#exec with a command array uses the first element as the command name and the second as the argv[0] value
fails:Kernel#exec with a command array coerces the argument using to_ary
fails:Kernel.exec raises an ArgumentError if the command includes a null byte
fails:Kernel.exec raises Errno::EACCES when passed a directory
fails:Kernel.exec unsets other environment variables when given a true :unsetenv_others option
fails:Kernel.exec sets the current directory when given the :chdir option
Expand Down
13 changes: 11 additions & 2 deletions src/org/jruby/RubyKernel.java
Expand Up @@ -1755,8 +1755,17 @@ public static IRubyObject _exec_internal(ThreadContext context, IRubyObject recv

private static IRubyObject execCommon(Ruby runtime, IRubyObject env, IRubyObject prog, IRubyObject options, IRubyObject[] args) {
// This is a fairly specific hack for empty string, but it does the job
if (args.length == 1 && args[0].convertToString().isEmpty()) {
throw runtime.newErrnoENOENTError(args[0].convertToString().toString());
if (args.length == 1) {
RubyString command = args[0].convertToString();
if (command.isEmpty()) {
throw runtime.newErrnoENOENTError(command.toString());
} else {
for(byte b : command.getBytes()) {
if (b == 0x00) {
throw runtime.newArgumentError("string contains null byte");
}
}
}
}

ThreadContext context = runtime.getCurrentContext();
Expand Down

0 comments on commit d90f2db

Please sign in to comment.