The MASM Forum Archive 2004 to 2012

Project Support Forums => MASM32 => Topic started by: brethren on March 01, 2011, 05:53:05 PM

Title: GetCL bug
Post by: brethren on March 01, 2011, 05:53:05 PM
from the masm32 docs
QuoteThe buffer for the returned argument should be set at 128 bytes in length which is the maximum allowable.

if a commandline arg is larger than 128 bytes then the assigned buffer overflows. try overflowing it in olly and you'll see. for example if you were to pass a commandline arg of say 200 's' character, olly will give the error "dont know how to continue because memory at address 73737373 is not readable. Try to change EIP or pass exception to program".
test program

INCLUDE \masm32\include\masm32rt.inc

.data?
buf BYTE 128 DUP(?)

.code
start:

INVOKE GetCL, 1, ADDR buf
print ustr$(eax), 13, 10                   ;return value for GetCL
print ustr$(len(ADDR buf)), 13, 10         ;length of string returned from GetCL
print ADDR buf, 13, 10                     ;display the string

exit
END start
Title: Re: GetCL bug
Post by: jj2007 on March 01, 2011, 09:33:47 PM
Conventional wisdom was that commandlines would not exceed 128 chars. But I tested it with a batch file and a 1024+ arg, and it works fine. MasmBasic could handle 640kB, but it seems 32767 bytes is Windows' limit - The Old New Thing: What is the command line length limit? (http://blogs.msdn.com/b/oldnewthing/archive/2003/12/10/56028.aspx)