Repository navigation
Fixes 1654: Fixed win32print.DeviceCapabilities() returning strings with junk in them. - #1660
Merged
Merged
Conversation
LincolnPuzey
force-pushed
the
fix_issue_1654
branch
from
January 31, 2021 10:38
b598055 to
20361e9
Compare
Contributor
Author
|
@mhammond when you have time, I would appreciate a review of this, thanks. Any suggestions of how I could add a test? |
mhammond
requested changes
Feb 1, 2021
mhammond
left a comment
Owner
There was a problem hiding this comment.
Thanks for this!
I can't think of a good way to test this. Do you mind making the change I suggest?
| for (bufindex = 0; bufindex < result; bufindex++) { | ||
| if (*(retname + retsize - 1) == 0) | ||
| // check if returned string contains null character | ||
| bool contains_null = false; |
Owner
There was a problem hiding this comment.
This could probably be simplified - it looks like retsize_index is always the actual string length (ie, is what we could pass to PyWinObject_FromTCHAR in both cases. So maybe rename it to, say, actual_ret_size and you can kill contains_null and the later if?
Contributor
Author
There was a problem hiding this comment.
Yep makes sense, will change.
…them. Previously this code would ZeroMemory() the output buffer before passing it to DeviceCapabilities(), and then assume that only characters in each string would be changed, i.e. the characters following the null-terminator would remain null. So it would only check if the last character in each string was null, to check if the string was null-terminated. This assumption is wrong - sometimes DeviceCapabilities() sets the characters after null to junk. Now every character in the returned buffer is checked for being null before falling back to the case where the string takes up all available space. mhammond#1654
LincolnPuzey
force-pushed
the
fix_issue_1654
branch
from
February 1, 2021 12:37
20361e9 to
e858c8a
Compare
Contributor
Author
|
Fixes Issue #1654 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously this code would
ZeroMemory()the output buffer before passing it toDeviceCapabilities(),and then assume that only characters in each string would be changed, i.e. the characters following
the null-terminator would remain null.
So it would only check if the last character in each string was null, to check if the string was null-terminated.
This assumption is wrong - sometimes
DeviceCapabilities()sets the characters after null to junk.Now every character in the returned buffer is checked for being null before falling back to the case where the
string takes up all available space.