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

Fix Windows command escape for \" #7092

Merged
merged 2 commits into from Feb 1, 2021

Conversation

Al2Klimov
Copy link
Member

fixes #4849

@Al2Klimov Al2Klimov requested a review from dnsmichi April 8, 2019 09:59
@mcktr mcktr added bug Something isn't working area/windows Windows agent and plugins labels Apr 9, 2019
@Al2Klimov Al2Klimov requested review from N-o-X and removed request for dnsmichi November 13, 2019 12:08
@Al2Klimov Al2Klimov requested review from dnsmichi and removed request for N-o-X December 3, 2019 12:56
@Al2Klimov Al2Klimov added this to the 2.12.0 milestone Jan 7, 2020
@dnsmichi dnsmichi removed this from the 2.12.0 milestone Jan 8, 2020
@Al2Klimov Al2Klimov added this to the 2.13.0 milestone Jan 22, 2020
@htriem
Copy link
Contributor

htriem commented Jan 23, 2020

@Al2Klimov Please add a test protocol for before and after.

@Al2Klimov
Copy link
Member Author

Roger.

@Al2Klimov Al2Klimov self-assigned this Jan 23, 2020
@Al2Klimov Al2Klimov removed the request for review from dnsmichi January 23, 2020 12:06
@Al2Klimov
Copy link
Member Author

Test case

Config

object CheckCommand "args2idsl" {
	command = [ PluginDir + "/args2idsl.exe", "$args2idsl$" ]
}

object Host "lolcat" {
	check_command = "args2idsl"
	check_interval = 1s
	vars.args2idsl = {{{ !"#$$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
" \" \\" \\\" \\\\"}}}
}

Plugin

https://github.com/Al2Klimov/args2idsl

Test protocol

Before

Bildschirmfoto 2020-01-23 um 13 32 03

After

Bildschirmfoto 2020-01-23 um 13 35 28

@Al2Klimov Al2Klimov removed their assignment Jan 23, 2020
@Al2Klimov Al2Klimov requested a review from htriem January 23, 2020 12:44
@Al2Klimov Al2Klimov added this to To review in v2.13.0 merge window Mar 12, 2020
@Al2Klimov Al2Klimov requested review from julianbrost and removed request for htriem November 13, 2020 15:54
@julianbrost
Copy link
Contributor

Enough Windows Escaping for today, what a dumpster fire. I'll revisit this next year but one thing I already know that will be part of the review: test cases for this would be nice, ideally some that also pass the result through CommandLineToArgvW.

Notes for my future self that might be helpful for the review:

Copy link
Contributor

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote some test for this, see https://github.com/Icinga/icinga2/compare/jbrost/windows-escape-args (that is your commit rebased to the current master + a commit adding tests).

Without your fix:

   70/110 Test  #70: base-base_utility/EscapeCreateProcessArg ................................***Failed    0.58 sec
  Running 1 test case...
C:/Users/Julian Brost/source/repos/icinga2/test/base-utility.cpp(107): error : in "base_utility/EscapeCreateProcessArg": CommandLineToArgvW() should return original value for foo"bar (got: foobar) [C:\Users\Julian Brost\source\repos\icinga2\build\RUN_TESTS.vcxproj]
C:/Users/Julian Brost/source/repos/icinga2/test/base-utility.cpp(103): error : in "base_utility/EscapeCreateProcessArg": CommandLineToArgvW() should find 2 arguments for "foo bar" [C:\Users\Julian Brost\source\repos\icinga2\build\RUN_TESTS.vcxproj]
C:/Users/Julian Brost/source/repos/icinga2/test/base-utility.cpp(107): error : in "base_utility/EscapeCreateProcessArg": CommandLineToArgvW() should return original value for "foo bar" (got: foo) [C:\Users\Julian Brost\source\repos\icinga2\build\RUN_TESTS.vcxproj]
C:/Users/Julian Brost/source/repos/icinga2/test/base-utility.cpp(103): error : in "base_utility/EscapeCreateProcessArg": CommandLineToArgvW() should find 2 arguments for " \" \\" \\\" \\\\" [C:\Users\Julian Brost\source\repos\icinga2\build\RUN_TESTS.vcxproj]
C:/Users/Julian Brost/source/repos/icinga2/test/base-utility.cpp(107): error : in "base_utility/EscapeCreateProcessArg": CommandLineToArgvW() should return original value for " \" \\" \\\" \\\\" (got: ) [C:\Users\Julian Brost\source\repos\icinga2\build\RUN_TESTS.vcxproj
]
C:/Users/Julian Brost/source/repos/icinga2/test/base-utility.cpp(103): error : in "base_utility/EscapeCreateProcessArg": CommandLineToArgvW() should find 2 arguments for  !"#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~ " \" \\" \\\" \\\\" [C:\Users\Julian Brost\source\repos\ici
nga2\build\RUN_TESTS.vcxproj]
C:/Users/Julian Brost/source/repos/icinga2/test/base-utility.cpp(107): error : in "base_utility/EscapeCreateProcessArg": CommandLineToArgvW() should return original value for  !"#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~ " \" \\" \\\" \\\\" (got:  !#$$%&'()*+,-./09:;<=>?@AZ[
\]^_`az{|}~) [C:\Users\Julian Brost\source\repos\icinga2\build\RUN_TESTS.vcxproj]

  *** 7 failures are detected in the test module "icinga2"

With your fix:

          Start  70: base-base_utility/EscapeCreateProcessArg
   70/110 Test  #70: base-base_utility/EscapeCreateProcessArg ................................   Passed    0.75 sec

There are still two things that could be improved about the tests:

  • Currently just the function body is in #ifdef _WIN32, maybe this can be done better and the whole test can be excluded on non-Windows.
  • On my machine, when running the test, it complains about leaked memory, but I don't see where this should leak anything. (Failed) tests additionally output the following:
    Detected memory leaks!
    Dumping objects ->
    {29934} normal block at 0x000001F773C3F890, 88 bytes long.
     Data: <   s       s    > D0 EF C3 73 F7 01 00 00 10 E7 C3 73 F7 01 00 00
    {29933} normal block at 0x000001F773C3E710, 88 bytes long.
     Data: <p  s       s    > 70 F0 C3 73 F7 01 00 00 D0 EF C3 73 F7 01 00 00
    {29932} normal block at 0x000001F773C3F070, 88 bytes long.
     Data: <   s       s    > D0 EF C3 73 F7 01 00 00 10 E7 C3 73 F7 01 00 00
    {29931} normal block at 0x000001F773BD1D90, 16 bytes long.
     Data: <X  s            > 58 1A 90 73 F7 01 00 00 00 00 00 00 00 00 00 00
    {29930} normal block at 0x000001F773C3EFD0, 88 bytes long.
     Data: <p  s       s    > 70 F0 C3 73 F7 01 00 00 10 E7 C3 73 F7 01 00 00
    

@Al2Klimov
Copy link
Member Author

Tests LGTM. No idea where a memory leak could come from. Feel free to push the tests commit on this branch.

v2.13.0 merge window automation moved this from To review to Approved Jan 29, 2021
@Al2Klimov Al2Klimov merged commit dbdfe18 into master Feb 1, 2021
v2.13.0 merge window automation moved this from Approved to Merged Feb 1, 2021
@icinga-probot icinga-probot bot deleted the bugfix/command-escape-windows-4849 branch February 1, 2021 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/windows Windows agent and plugins bug Something isn't working
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[dev.icinga.com #13469] Command escape is broken for Windows
5 participants