horeah / PyCmd

Improved interactive experience for Windows' cmd.exe
GNU Lesser General Public License v3.0
23 stars 6 forks source link

Access is denied. #16

Closed Dominiquini closed 9 months ago

Dominiquini commented 9 months ago

Every time I start this application, this was printed in the screen:

Access is denied.
Access is denied.
Access is denied.

Welcome to PyCmd 20240206-x64!

F:\Downloads\PC-20240206-w64\PyCmd>

The message "Access is denied." is also printed 3 times after every command that I run inside PyCmd!

App Version: 20240206 OS Version: Windows 10 x64

Thanks.

horeah commented 9 months ago

This is quite surprising as the new version doesn't change any kind of file access at all!

Is the command history and the directory history (Alt-D) properly persisted between PyCmd sessions?

Could this be yet another misguided attempt at "security" from Microsoft? Is the old version (20230829) started from the same directory (F:\Downloads)? Did you get some prompt to allow the application to run, first time after downloading?

Dominiquini commented 9 months ago

This is quite surprising as the new version doesn't change any kind of file access at all!

Is the command history and the directory history (Alt-D) properly persisted between PyCmd sessions?

Yes. The history is persisted and retrieved in both versions!

Could this be yet another misguided attempt at "security" from Microsoft? Is the old version (20230829) started from the same directory (F:\Downloads)? Did you get some prompt to allow the application to run, first time after downloading?

Yes. I tested both versions in the same parent folder with the same access rights!

Is there anything more that I could help?

Thanks.

horeah commented 9 months ago

The easiest way to debug this would be for you to get the source code and try to run it directly with Python (there are some instructions in the README.txt); this would allow you to easily add some debug prints e.g. throughout run_command().

If this is not feasible, I can ask you to try a few things so that we get more data points, e.g.:

  1. are the "Access is denied" messages printed also for a simple cd some-dir command?
  2. is the environment properly captured? e.g. after you set MY_ENV_VAR=5 does PyCmd complete %MY_EN when you press TAB?
  3. after running some command (and seeing the "Access is denied" messages), what is inside the latest tmpfile? (you can find it in %APPDATA%\PyCmd\tmp, it should be the most recently modified file in that folder)

Thank you!

On Wed, Feb 21, 2024 at 6:16 PM Rafael Baboni Dominiquini < @.***> wrote:

This is quite surprising as the new version doesn't change any kind of file access at all!

Is the command history and the directory history (Alt-D) properly persisted between PyCmd sessions?

Yes. The history is saved and persisted in both versions!

Could this be yet another misguided attempt at "security" from Microsoft? Is the old version (20230829) started from the same directory (F:\Downloads)? Did you get some prompt to allow the application to run, first time after downloading?

Yes. I tested both versions in the same parent folder with the same access rights!

Is there anything more that I could help?

Thanks.

— Reply to this email directly, view it on GitHub https://github.com/horeah/PyCmd/issues/16#issuecomment-1957158498, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMLQKCHLPPEI5WWNGDPOMDYUYMVFAVCNFSM6AAAAABDSELT6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJXGE2TQNBZHA . You are receiving this because you commented.Message ID: @.***>

Dominiquini commented 9 months ago
  1. are the "Access is denied" messages printed also for a simple cd some-dir command? No. The 'cd' command doesn't throw "Access denied"!

  2. is the environment properly captured? e.g. after you set MY_ENV_VAR=5 does PyCmd complete %MY_EN when you press TAB? The autocomplete works fine, but each command throws "Access denied" message!

  3. after running some command (and seeing the "Access is denied" messages), what is inside the latest tmpfile? (you can find it in %APPDATA%\PyCmd\tmp, it should be the most recently modified file in that folder) tmp4nz7sbg6.txt

Screenshot: WindowsTerminal_gmg9ahpoyZ

I'll test it running with the source code in a little while!

Thanks

horeah commented 9 months ago

Thanks for taking time to look into this; to me the mystery deepens as I can spot nothing wrong with the results you posted -- everything looks normal (except for the "Access is denied" of course), including the contents of the temp file.

If you are able to add some debug prints, I recommend you start at the os.system() call in PyCmd.py:722; maybe print the actual command, and print a "before" and "after" line.

Dominiquini commented 9 months ago

I have done some more tests and find out that the commit that introduces the bug is this: af80779ac34d3c5893944d5d0d81c54d7adcff91

Before this commit: 9199548b82770ff310c2aea9df8ffdb2957d0f6e Command: "pwd &set > "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp3l30xtub" & echo CD="!CD!" >> "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp3l30xtub" & echo DATE="!DATE!" >> "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp3l30xtub" & echo ERRORLEVEL="!ERRORLEVEL!" >> "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp3l30xtub" & echo RANDOM="!RANDOM!" >> "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp3l30xtub" & echo TIME="!TIME!" >> "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp3l30xtub""

Master: 7292e294d595a9c68c85a1437fb2106d6f654884 Command: %COMSPEC% /V:ON /c "pwd &set > "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp6mx1eqqu" & echo CD="!CD!" >> "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp6mx1eqqu" & echo DATE="!DATE!" >> "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp6mx1eqqu" & echo ERRORLEVEL="!ERRORLEVEL!" >> "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp6mx1eqqu" & echo RANDOM="!RANDOM!" >> "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp6mx1eqqu" & echo TIME="!TIME!" >> "C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp6mx1eqqu"& echo ===PUSHD STACK BEGIN=== >> C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp6mx1eqqu& pushd >> C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp6mx1eqqu& echo ===PUSHD STACK END=== >> C:\Users\Rafael Dominiquini\AppData\Roaming\PyCmd\tmp\tmp6mx1eqqu"

I hope this could help you!

Thanks.

horeah commented 9 months ago

I think we are getting close!

Examining your debug output shows that the echoing of the new "PUSH STACK" lines does not quote the file name; this works as long as the %APPDATA% does not contain whitespace -- but yours does!

Can you try to replace tmpfile with '"' + tmpfile + '"' in PyCmd.py lines 718-720 and see if it fixes the problem?

Just to be extra clear: I am referring to lines 718-720 from the master version of PyCmd.py, they currently look like this:

        command += '& echo ===PUSHD STACK BEGIN=== >> ' + tmpfile
        command += '& pushd >> ' + tmpfile
        command += '& echo ===PUSHD STACK END=== >> ' + tmpfile

but I think they should look like this:

        command += '& echo ===PUSHD STACK BEGIN=== >> ' + '"' + tmpfile + '"'
        command += '& pushd >> ' + '"' + tmpfile + '"'
        command += '& echo ===PUSHD STACK END=== >> ' + '"' + tmpfile + '"'

Thanks!

Dominiquini commented 9 months ago

I think we are getting close!

Examining your debug output shows that the echoing of the new "PUSH STACK" lines does not quote the file name; this works as long as the %APPDATA% does not contain whitespace -- but yours does!

Can you try to replace tmpfile with '"' + tmpfile + '"' in PyCmd.py lines 718-720 and see if it fixes the problem?

Just to be extra clear: I am referring to lines 718-720 from the master version of PyCmd.py, they currently look like this:

        command += '& echo ===PUSHD STACK BEGIN=== >> ' + tmpfile
        command += '& pushd >> ' + tmpfile
        command += '& echo ===PUSHD STACK END=== >> ' + tmpfile

but I think they should look like this:

        command += '& echo ===PUSHD STACK BEGIN=== >> ' + '"' + tmpfile + '"'
        command += '& pushd >> ' + '"' + tmpfile + '"'
        command += '& echo ===PUSHD STACK END=== >> ' + '"' + tmpfile + '"'

Thanks!

It worked here! You will made another build with this fix?

Thanks.

horeah commented 9 months ago

You will made another build with this fix?

Yes, this is a serious bug and I will have to issue a new release soon. Until then, you can use the attached PyCmd-20240223-w64.zip

horeah commented 9 months ago

Until then, you can use the attached PyCmd-20240223-w64.zip

@Dominiquini did you have time to try out the build I uploaded? Does it work fine for you?

Dominiquini commented 9 months ago

Until then, you can use the attached PyCmd-20240223-w64.zip

@Dominiquini did you have time to try out the build I uploaded? Does it work fine for you?

It worked!

Thanks.

horeah commented 9 months ago

The fix is included in release 20240228; thanks @Dominiquini for finding and investigating this!