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

Install-ChocolateyInstallPackage.ps1 adds trailing space to silent args #2345

Closed
majkinetor opened this issue Sep 4, 2021 · 23 comments · Fixed by #3113
Closed

Install-ChocolateyInstallPackage.ps1 adds trailing space to silent args #2345

majkinetor opened this issue Sep 4, 2021 · 23 comments · Fixed by #3113
Assignees
Milestone

Comments

@majkinetor
Copy link

majkinetor commented Sep 4, 2021

In powershell function Install-ChocolateyInstallPackage trailing space is added to silentArgs:

$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$silentArgs $additionalInstallArgs" $fileFullPath -validExitCodes $validExitCodes -workingDirectory $workingDirectory

The problematic part is statement parameter of function Start-ChocolateyProcessAsAdmin which gets into it as "$silentArgs $additionalInstallArgs".

With Total Commander for example, passing silentArgs as '/AHDU c:\totalcmd' gets executed as '/AHDU c:\totalcmd ' (notice the trailing space). Then TC tries to create folder 'c:\totalcmd ' with space at the end and it fails.

To prove it is the problem and after looking into source code I used workaround solution for that package:

With that code package installation works which proves that statement parameter handling is problematic and can not be set in this case. This solution is however flagged by gallery validator.

To fix it, something like this will work:

$statements = $silentArgs 
if ($additionalInstallArgs) { $statements += " $additionalInstallArgs" } 
$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin $statements $fileFullPath -validExitCodes $validExitCodes -workingDirectory $workingDirectory 
@gep13
Copy link
Member

gep13 commented Sep 4, 2021

@majkinetor I am not sure if I follow the problem that you are seeing here.

Can you please go back and update this issue using the issue template for reporting a bug? This includes a steps to reproduce section, which will help in understanding the problem that you are seeing.

Thanks

@majkinetor
Copy link
Author

majkinetor commented Sep 4, 2021

[moved]

1 similar comment
@majkinetor
Copy link
Author

majkinetor commented Sep 4, 2021

[moved]

@gep13
Copy link
Member

gep13 commented Sep 6, 2021

@majkinetor thank you for the additional information, that helps to understand the problem.

Are you able to update the original issue with all that information so that it is in one place?

Thanks

@majkinetor
Copy link
Author

majkinetor commented Sep 6, 2021

Sure. Should I PR this change, since its obviously buggy for some class of tools ?

@gep13
Copy link
Member

gep13 commented Sep 6, 2021

Yip, happy to accept a PR which addresses this problem.

If we can put some tests around this as well, that would be great, but I don't think that would be possible.

@majkinetor
Copy link
Author

majkinetor commented Sep 6, 2021

Would testing the change by patching my local system be good enough ? I would change the Install-ChocolateyInstallPackage.ps1 and force install TC package with silentArgs set in the Windows Sandbox and if it doesn't fail, I will call it a day. I can provide videos or logs of pre/post installations.

Changed the initial description.

@gep13
Copy link
Member

gep13 commented Sep 6, 2021

In terms of "developer" testing, what you have suggested would be great, yes.

What I was thinking about is how to introduce automated tests, to ensure that this isn't regressed in future releases.

We don't have any infrastructure in this repository to add those style of tests, but we do have some internally, so we may have to look to getting a test(s) added there to cover this bug.

@majkinetor
Copy link
Author

In the meantime, since package is highly used, should I trick the validator or can you (or somebody else) "promote" the TC package ?

@gep13
Copy link
Member

gep13 commented Sep 6, 2021

It is possible to provide an exemption (at the package version level) from package-validation, so if you reply to the moderation thread with a request for exemption, pointing at this issue, one of the moderators should be able to pick it up.

@majkinetor
Copy link
Author

I will do that. Thanks.

@majkinetor
Copy link
Author

Actually, I can't do that, since its chocolatey-community user behind the scenes.

@TheCakeIsNaOH
Copy link
Member

TheCakeIsNaOH commented Oct 6, 2021

I've added an exemption for the current version (10.0.0.20210903).

@gobalius
Copy link

gobalius commented Dec 17, 2022

@majkinetor did you ever create a PR of your proposed changes to choco/src/chocolatey.resources/helpers/functions/Install-ChocolateyInstallPackage.ps1?

@majkinetor
Copy link
Author

@gobalius, No.

@gobalius
Copy link

@majkinetor would you consider creating the PR? I think it's a low risk (unaffected packages will still work) and high gain (packages like totalcommander will not need the workaround and will pass the automatic check) situation.

TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Dec 24, 2022
This prevents the addition of a trailing space after silent arguments in
Install-ChocolateyInstallPackage when there are no additional arguments.
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Jan 6, 2023
This prevents the addition of a trailing space after silent arguments in
Install-ChocolateyInstallPackage when there are no additional arguments.
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Jan 13, 2023
This prevents the addition of a trailing space after silent arguments in
Install-ChocolateyInstallPackage when there are no additional arguments.
blami added a commit to blami/choco that referenced this issue Apr 12, 2023
Fix a bug where concatenating silentArgs and additionalInstallArgs adds
a trailing space at the end of silentArgs even when
additionalInstallArgs is empty. Such trailing space can change the
meaning of the last positional argument (that may contain spaces).

Final arguments are now created as space joined string arrays filtered
down to only non-empty items. Fix is applied to all installer types.

Fixes: chocolatey#2345
@blami
Copy link
Contributor

blami commented Apr 13, 2023

Hi, I am interested in fixing this (already raised a PR which I believe addresses the issue) as it blocks me from using Chocolatey internally with our installers (that behave similarly to Total Commander).

I looked at previous two PRs and they seem inactive and I feel that solution one of them proposes (simply merging arguments without space in between) would break some other installers while my solution (not adding any spaces before empty strings) should work in those cases (same as draft above).

@blami
Copy link
Contributor

blami commented May 25, 2023

@gep13 I'm sorry to tag, not really sure what is process here to get the PR reviewed and eventually merged.

TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Jun 6, 2023
This prevents the addition of a trailing space after silent arguments in
Install-ChocolateyInstallPackage when there are no additional arguments.
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Jun 15, 2023
This prevents the addition of a trailing space after silent arguments in
Install-ChocolateyInstallPackage when there are no additional arguments.
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Jul 1, 2023
This prevents the addition of a trailing space after silent arguments in
Install-ChocolateyInstallPackage when there are no additional arguments.
@blami
Copy link
Contributor

blami commented Jul 9, 2023

@majkinetor I am sorry to tag, but is there anything I can do to have this PR reviewed and eventually merged? Is it just there's not enough reviewer bandwidth or is anything else missing on my side?

@majkinetor
Copy link
Author

@blami , sorry, I am just a regular guy, not a choco employee. I don't think the outcome deserves the effort that is requested here.

@blami
Copy link
Contributor

blami commented Aug 13, 2023

@gep13 is there anything from my side I can do to have this fix merged?

@pauby
Copy link
Member

pauby commented Aug 14, 2023

@blami We'll review the PR when we're ready to pull it in. The issue ha snot been assigned to a milestone as yet so it's not something we are currently working on.

@blami
Copy link
Contributor

blami commented Aug 14, 2023

@pauby Thanks for clarification, since there were earlier replies from assignee, particularly this one:

Yip, happy to accept a PR which addresses this problem.

I thought this issue is already on radar. I understand the situation now and will wait until this makes it to some milestone.

@gep13 gep13 added this to the 2.3.0 milestone Dec 14, 2023
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Jan 10, 2024
This prevents the addition of a trailing space after silent arguments in
Install-ChocolateyInstallPackage when there are no additional arguments.
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Apr 28, 2024
This prevents the addition of a trailing space after silent arguments in
Install-ChocolateyInstallPackage when there are no additional arguments.
corbob pushed a commit to blami/choco that referenced this issue May 6, 2024
Fix a bug where concatenating silentArgs and additionalInstallArgs adds
a trailing space at the end of silentArgs even when
additionalInstallArgs is empty. Such trailing space can change the
meaning of the last positional argument (that may contain spaces).

Final arguments are now created as space joined string arrays filtered
down to only non-empty items. Fix is applied to all installer types.

Fixes: chocolatey#2345
corbob added a commit to blami/choco that referenced this issue May 6, 2024
This adds a set of tests to validate that the spaces that may be passed
in by the package are honoured, while not introducing erroneous spaces.
corbob added a commit to blami/choco that referenced this issue May 6, 2024
This adds a set of tests to validate that the spaces that may be passed
in by the package are honoured, while not introducing erroneous spaces.
corbob added a commit to blami/choco that referenced this issue May 7, 2024
This adds a set of tests to validate that the spaces that may be passed
in by the package are honoured, while not introducing erroneous spaces.
corbob pushed a commit to blami/choco that referenced this issue May 7, 2024
Fix a bug where concatenating silentArgs and additionalInstallArgs adds
a trailing space at the end of silentArgs even when
additionalInstallArgs is empty. Such trailing space can change the
meaning of the last positional argument (that may contain spaces).

Final arguments are now created as space joined string arrays filtered
down to only non-empty items. Fix is applied to all installer types.

It is expected not to manipulate the arguments themselves in case there
are any spaces that the package maintainer has included.
corbob added a commit to blami/choco that referenced this issue May 7, 2024
This adds a set of tests to validate that the spaces that may be passed
in by the package are honoured, while not introducing erroneous spaces.
corbob pushed a commit to blami/choco that referenced this issue May 21, 2024
Fix a bug where concatenating silentArgs and additionalInstallArgs adds
a trailing space at the end of silentArgs even when
additionalInstallArgs is empty. Such trailing space can change the
meaning of the last positional argument (that may contain spaces).

Final arguments are now created as space joined string arrays filtered
down to only non-empty items. Fix is applied to all installer types.

It is expected not to manipulate the arguments themselves in case there
are any spaces that the package maintainer has included.
corbob added a commit to blami/choco that referenced this issue May 21, 2024
This adds a set of tests to validate that the spaces that may be passed
in by the package are honoured, while not introducing erroneous spaces.
corbob pushed a commit to blami/choco that referenced this issue May 22, 2024
Fix a bug where concatenating silentArgs and additionalInstallArgs adds
a trailing space at the end of silentArgs even when
additionalInstallArgs is empty. Such trailing space can change the
meaning of the last positional argument (that may contain spaces).

Final arguments are now created as space joined string arrays filtered
down to only non-empty items. Fix is applied to all installer types.

It is expected not to manipulate the arguments themselves in case there
are any spaces that the package maintainer has included.
corbob added a commit to blami/choco that referenced this issue May 22, 2024
This adds a set of tests to validate that the spaces that may be passed
in by the package are honoured, while not introducing erroneous spaces.
gep13 added a commit that referenced this issue May 23, 2024
(#2345) Avoid any trailing spaces after silentArgs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants