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: prevent print crash on bad deviceName #21946

Merged
merged 2 commits into from Jan 31, 2020
Merged

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Jan 28, 2020

Description of Change

On Windows and macOS, Chromium's printing code will crash if a deviceName is provided, but is invalid on the network, i.e does not correspond to a printer that the caller machine is aware of. This bug has been present for a long time, but after playing around a bit I've determined that it's possible to catch faulty deviceNames by pulling out some of the printer validation code from Chromium. This PR adds that check for Windows and macOS as well as tests for the same.

Tested with:

win.webContents.on('did-finish-load', () => {
   win.webContents.print({deviceName: 'bad-printer-name'}, (success, reason) => {
      console.log(`printing ${success ? 'did' : 'did not'} succeed: ${reason}`)
   })
})

cc @ckerr @zcbenz

Checklist

Release Notes

Notes: Fixed a potential crash on faulty deviceNames in webContents.print().

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jan 28, 2020
@codebytere codebytere force-pushed the sanity-check-devicename branch 2 times, most recently from 8fde28f to 261f6d2 Compare January 28, 2020 22:06
shell/browser/api/atom_api_web_contents.cc Outdated Show resolved Hide resolved
shell/browser/api/atom_api_web_contents.cc Outdated Show resolved Hide resolved
shell/browser/api/atom_api_web_contents.cc Outdated Show resolved Hide resolved
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

LGTM

docs/api/webview-tag.md Outdated Show resolved Hide resolved
spec-main/api-web-contents-spec.ts Outdated Show resolved Hide resolved
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jan 29, 2020
@zcbenz zcbenz merged commit 2955c67 into master Jan 31, 2020
@release-clerk
Copy link

release-clerk bot commented Jan 31, 2020

Release Notes Persisted

Fixed a potential crash on faulty deviceNames in webContents.print().

@zcbenz zcbenz deleted the sanity-check-devicename branch January 31, 2020 02:49
@trop
Copy link
Contributor

trop bot commented Jan 31, 2020

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

@trop trop bot removed the target/7-1-x label Jan 31, 2020
@trop
Copy link
Contributor

trop bot commented Jan 31, 2020

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

@trop
Copy link
Contributor

trop bot commented Jan 31, 2020

I have automatically backported this PR to "8-x-y", please check out #21982

codebytere added a commit that referenced this pull request Feb 3, 2020
* fix: prevent print crash on bad deviceName

* address review feedback
@trop
Copy link
Contributor

trop bot commented Feb 3, 2020

@codebytere has manually backported this PR to "7-1-x", please check out #22012

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

Successfully merging this pull request may close these issues.

None yet

3 participants