Skip to content

fix: hard crash on invalid command line switches - #46004

Merged
ckerr merged 4 commits into
mainfrom
switch-check
Mar 26, 2025
Merged

ckerr merged 4 commits into
mainfrom
switch-check

Conversation

@codebytere

@codebytere codebytere commented Mar 13, 2025 •

Copy link
Copy Markdown
Member

Description of Change

Closes #45991.

Addresses an issue where poorly formed switched could cause a hard crash in Chromium since M134 by ensuring the switches are lowercased. Also improve the docs a little.

Checklist

Release Notes

Notes: Fixed an issue where badly formatted switches could cause crashes in app.commandLine functions.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Mar 13, 2025
@codebytere codebytere added target/35-x-y PR should also be added to the "35-x-y" branch. target/36-x-y PR should also be added to the "36-x-y" branch. labels Mar 13, 2025
@codebytere codebytere changed the title fix: hard crash on invalid command line switch fix: hard crash on invalid command line switches Mar 13, 2025
@codebytere codebytere added the semver/patch backwards-compatible bug fixes label Mar 13, 2025

@nikwen nikwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Only had a look at the docs changes. I like them. Thanks for including them in the PR!

Comment thread docs/api/command-line.md Resolved
@codebytere
codebytere requested a review from ckerr March 13, 2025 14:10
@deepak1556

deepak1556 commented Mar 13, 2025 •

Copy link
Copy Markdown
Member

Curious, what is the decision behind not having to auto convert the switch names to lowercase instead of throwing an error given that is what the runtime accepts ?

@codebytere

Copy link
Copy Markdown
Member Author

@deepak1556 i think changing it out from under the user is pretty unintuitive behavior, especially since later when/if they go to fetch it it'll be different than what they passed

@deepak1556

deepak1556 commented Mar 13, 2025 •

Copy link
Copy Markdown
Member

Not sure I follow, the flags accepted by these apis are chromium specific and they should be in the format chromium expects. Why would the return value format matter in this case ?

If the api accepts custom flags then this fix makes sense.

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Mar 14, 2025
@codebytere

Copy link
Copy Markdown
Member Author

@deepak1556 fair enough - i can make that change :)

@codebytere

Copy link
Copy Markdown
Member Author

@deepak1556 yep, fixed!

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like this change. It's simpler than the previous iteration and should work fine for most cases.

But if we're just going to silently convert the switches passed in by users, this would break any tool that has case-specific commmand-line arguments like grep's -l and -L arguments.

Even though there's no way to support case-sensitive switches anymore, silently converting them is still a potentially-breaking change. This needs to be documented in breaking-changes.md

@deepak1556

Copy link
Copy Markdown
Member

👍 for documenting as breaking change

To clarify, app.commandLine was only meant to handle chromium switches which was never case sensitive. For ex,

app.commandLine.appendSwitch('CustomFlag', 'value') will not be passed down to any of the child processes. If applications were using to control the behavior of main process then it should be done via process.argv.

@ckerr

ckerr commented Mar 21, 2025

Copy link
Copy Markdown
Member

LGTM other than updating the breaking changes doc 👍

@ckerr
ckerr merged commit d2c2261 into main Mar 26, 2025
@ckerr
ckerr deleted the switch-check branch March 26, 2025 13:14
@release-clerk

release-clerk Bot commented Mar 26, 2025

Copy link
Copy Markdown

Release Notes Persisted

Fixed an issue where badly formatted switches could cause crashes in app.commandLine functions.

@trop

trop Bot commented Mar 26, 2025

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "36-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot removed the target/36-x-y PR should also be added to the "36-x-y" branch. label Mar 26, 2025
@trop

trop Bot commented Mar 26, 2025

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "35-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot added needs-manual-bp/36-x-y needs-manual-bp/35-x-y and removed target/35-x-y PR should also be added to the "35-x-y" branch. labels Mar 26, 2025
ckerr pushed a commit that referenced this pull request Apr 2, 2025
* fix: hard crash on invalid command line switch

* Update docs/api/command-line.md

Co-authored-by: Niklas Wenzel <[email protected]>

* chore: feedback from review

* docs: Add breaking change note

---------

Co-authored-by: Niklas Wenzel <[email protected]>
@trop

trop Bot commented Apr 2, 2025

Copy link
Copy Markdown
Contributor

@ckerr has manually backported this PR to "36-x-y", please check out #46446

ckerr pushed a commit that referenced this pull request Apr 3, 2025
* fix: hard crash on invalid command line switch

* Update docs/api/command-line.md

Co-authored-by: Niklas Wenzel <[email protected]>

* chore: feedback from review

* docs: Add breaking change note

---------

Co-authored-by: Niklas Wenzel <[email protected]>
ckerr added a commit that referenced this pull request Apr 4, 2025
fix: hard crash on invalid command line switches (#46004)

* fix: hard crash on invalid command line switch

* Update docs/api/command-line.md



* chore: feedback from review

* docs: Add breaking change note

---------

Co-authored-by: Shelley Vohr <[email protected]>
Co-authored-by: Niklas Wenzel <[email protected]>
@trop trop Bot added merged/36-x-y PR was merged to the "36-x-y" branch. and removed in-flight/36-x-y labels Apr 4, 2025
@trop

trop Bot commented Apr 14, 2025

Copy link
Copy Markdown
Contributor

@codebytere has manually backported this PR to "35-x-y", please check out #46631

@trop trop Bot added in-flight/35-x-y merged/35-x-y PR was merged to the "35-x-y" branch. and removed needs-manual-bp/35-x-y in-flight/35-x-y labels Apr 14, 2025
kigh-ota pushed a commit to kigh-ota/electron that referenced this pull request Sep 30, 2025
* fix: hard crash on invalid command line switch

* Update docs/api/command-line.md

Co-authored-by: Niklas Wenzel <[email protected]>

* chore: feedback from review

* docs: Add breaking change note

---------

Co-authored-by: Niklas Wenzel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/35-x-y PR was merged to the "35-x-y" branch. merged/36-x-y PR was merged to the "36-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

app.commandLine.getSwitchValue throws on uppercase letters

6 participants