Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug - Menu >> File >> Run for long command line gets truncated #394

Closed
ScottHollows opened this issue Jun 5, 2023 · 6 comments
Closed

Comments

@ScottHollows
Copy link

Symptoms
Running a very long command from Menu >> File >> Run results in the command getting truncated somewhere around 255 character and some extra junk characters get added to the command

Example

  1. Menu >> File >> Run

  2. Enter this in the command line field

MyProgram.exe /aaaaaaaaaaaaaaaaaa=aaaaaaaaaaaaaaaaaaaaa /bbbbbbbbbbbbbbbbbbbb=bbbbbbbbbbbbbbbbbbbbbbbbb /cccccccccccccccccc=cccccccccccccccc /ddddddddddddddd=dddddddddddddddd /eeeeeeeeeeeeeeeeeee=eeeeeeeeeeeeeeeeee /ffffffffffffffff=ffffffffffffffffffffff /ggggggggggggggggg=ggggggggggggggggggggggggggg /hhhhhhhhhhhhhhhhhhhhh=hhhhhhhhhhhhhhhhhhh /iiiiiiiiiiiiiiiiiiiiiiii=iiiiiiiiiiiiiiiiiiiiii /jjjjjjjjjjjjjjjjjjjj=jjjjjjjjjjjjjjjjjjjjj /kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk=kkkkkkkkkkkkkkkkkkkkkkkkkk /llllllllllllllllllllll=lllllllllllllllllllll

  1. Press OK

  2. The command gets truncated around 255 characters and junk characters are added to the end

MyProgram.exe /aaaaaaaaaaaaaaaaaa=aaaaaaaaaaaaaaaaaaaaa /bbbbbbbbbbbbbbbbbbbb=bbbbbbbbbbbbbbbbbbbbbbbbb /cccccccccccccccccc=cccccccccccccccc /ddddddddddddddd=dddddddddddddddd /eeeeeeeeeeeeeeeeeee=eeeeeeeeeeeeeeeeee /ffffffffffffffff=fffffffffffffffffffff??? d

Use Case
In my application, the field values can be specified on the command line which can result in a very long command line

Change Request
Please remove the limit or increase it to perhaps 1000 characters

@schinagl
Copy link
Contributor

schinagl commented Jun 5, 2023

Are you using Winfile 10.2.0.0?
How did you determine that the args were garbled? Printing the args from MyProgram.exe?

If I debug Winfile the args 'leave' winfile via ShellExecute() in shape.
Are you sure the problem is not in MyProgram.exe when printing the args?
As far as I remember command lines are limited to 255 characters, but I could be wrong.

@malxau
Copy link
Contributor

malxau commented Jun 6, 2023

@ScottHollows I'd second schinagl's question - which release are you using? Also, which version of Windows?

I think the limitation is in RunDlgProc. Prior to #340 , this was limited to 260 chars (total.) In the latest release this should be over 1000.

Unfortunately that doesn't explain:

  • How the text is entered, because the control's width is limited to the buffer width via EM_LIMITTEXT
  • Garbled characters, which smells like a buffer overflow. Here the code is using lstrcpy into stack based buffers, but it "knows" that if all the text fit into the original buffer, substrings have to fit into component buffers. Also, GetDlgItemText is documented to NULL terminate on truncate.

Originally the code used a different constant for the parameter buffer length compared to the total buffer length, which seems unsafe, but as far as I can tell in this repo they always had the same value. If there was a build where RUN_LENGTH < MAXPATHLEN, this could happen.

@schinagl
Copy link
Contributor

schinagl commented Jun 6, 2023

@malxau : I hooked up with the debugger, then exactly entered the string specified by @ScottHollows, and was able see that it was fed into ShellExecute() exactly the right way.

So @ScottHollows please check MyProgramm.exe if it handles args properly

@ScottHollows
Copy link
Author

I wrote a test program that shows the parameters passed in to it and the length of the parameters

It runs ok from a DOS command line with 5000 characters
It also runs ok when called from a DOS batch program with 5000 characters

When I run it from File Manager > File Run it gets truncated around 1000 characters, with a bit of wiggle room that is probably the length of the program name

I have identified at least one issue where the File Run > Command Line field is limited to 1000 characters so there is no way to test parameters longer than that That 1000 limit is longer than the original 255 that I reported in my original post so must have done that test incorrectly - sorry about that. At a guess, I probably ran an older version of File Manager or I was running it in an virtual machine with an old version of Windows
When I run that same test now in Windows 10 (22H2) it correctly shows all 255 char

So, my original post was incorrect and the limit is around 1000 rather than the 255 that I reported

Since this is under review, can the limit for that Command Line field be increased to maybe 5000 characters ?

@schinagl
Copy link
Contributor

schinagl commented Jun 9, 2023

With #340 the length of path and all internal strings was increased to 1024.
#340 is part of 10.2.0.0

Thus the arguments of a command passed to File/Run can be 1024 characters.

I suggest to use .bat files for arguments longer than 1024 characters, because handling of so many characters in this tiny File/Run box is error prone.

@ScottHollows
Copy link
Author

Thanks for looking into this.

I am closing this issue now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants