Skip to content

Commit 99b00fd

Browse files
Create argv in prepare_args
1 parent 0ec1144 commit 99b00fd

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/crystal/system/unix/process.cr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ struct Crystal::System::Process
307307
pid
308308
end
309309

310-
def self.prepare_args(command : String, args : Enumerable(String)?, shell : Bool) : {String, Array(String)}
310+
def self.prepare_args(command : String, args : Enumerable(String)?, shell : Bool) : {String, UInt8**}
311311
if shell
312312
command = %(#{command} "${@}") unless command.includes?(' ')
313313
shell_args = ["/bin/sh", "-c", command, "sh"]
@@ -320,11 +320,12 @@ struct Crystal::System::Process
320320
shell_args.concat(args)
321321
end
322322

323-
{"/bin/sh", shell_args}
323+
{"/bin/sh", shell_args.map(&.check_no_null_byte.to_unsafe).to_unsafe}
324324
else
325325
command_args = [command]
326326
command_args.concat(args) if args
327-
{command, command_args}
327+
328+
{command, command_args.map(&.check_no_null_byte.to_unsafe).to_unsafe}
328329
end
329330
end
330331

@@ -345,8 +346,6 @@ struct Crystal::System::Process
345346
::Dir.cd(chdir) if chdir
346347

347348
pathname, argv = command_args
348-
argv = command_args.map &.check_no_null_byte.to_unsafe
349-
argv << Pointer(UInt8).null
350349

351350
lock_write { LibC.execvp(pathname, argv) }
352351
end

0 commit comments

Comments
 (0)