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
Fixes 1654: Fixed win32print.DeviceCapabilities() returning strings with junk in them. #1660
Conversation
b598055
to
20361e9
Compare
@mhammond when you have time, I would appreciate a review of this, thanks. Any suggestions of how I could add a test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
I can't think of a good way to test this. Do you mind making the change I suggest?
win32/src/win32print/win32print.cpp
Outdated
for (bufindex = 0; bufindex < result; bufindex++) { | ||
if (*(retname + retsize - 1) == 0) | ||
// check if returned string contains null character | ||
bool contains_null = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
20361e9
to
e858c8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Fixes Issue #1654 |
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.