Project

General

Profile

Actions

Bug #2016

closed

Windows (win32.c) command line argument parsing bug

Bug #2016: Windows (win32.c) command line argument parsing bug

Added by deleyd (David Deley) about 16 years ago. Updated over 14 years ago.

Status:
Rejected
Target version:
-
ruby -v:
1.9.1
Backport:
[ruby-core:25199]

Description

=begin
Fix:
file: \win32\win32.c
routine: rb_w32_cmdvector
line:
memcpy(p - ((slashes + 1) >> 1), p + (~slashes & 1),
base + len - p);

add 1 to the length so we include the trailing zero:
memcpy(p - ((slashes + 1) >> 1), p + (~slashes & 1),
base + len + 1 - p);
^^^

PROBLEM DESCRIPTION:
INCORRECT PARSING OF COMMAND LINE PARAMETERS
To Reproduce:
#simple show parameters program ShowParams.rb:
ARGV.each do|a|
puts "Argument: #{a}"
end

Try it with this command line:

ShowParams.rb hello\" goodbye friday
Argument: hello"\goodbye
Argument: goodbye
Argument: friday

(not sure where to report this as win32.c isn't a part of the Ruby core SVN, though it is in ruby-1.9.1-p129-i386-mswin32.zip)

Appears routine is trying to reproduce the Microsoft Windows C/C++ Command Line Parsing Rules. For more see my essay "How Command Line Parameters Are Parsed:How to properly escape the special characters in your command line parameters" at http://www.autohotkey.net/~deleyd/parameters/parameters.htm
=end

Actions

Also available in: PDF Atom