Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-36161: Use thread-safe function ttyname_r instead of unsafe one ttyname#14868
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
chibby0ne commented Jul 20, 2019 • edited by bedevere-bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-bot
Uh oh!
There was an error while loading. Please reload this page.
chibby0ne commented Jul 20, 2019
Hi all, I'm a new contributor and I've made a PR taking into account the discussion seen in the issue page. For the For the This is how a raised error would look when passing an invalid salt: |
chibby0ne commented Jul 20, 2019
I don't understand the error in the MacOS Builder: I don't understand since they are both unicode, and password is clearly utf-8 and the second argument are two If it were some codec issue wouldn't it fail in other OSes? Likewise for the other added test. |
mangrisano left a comment
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.
Hi and thank you for this PR and for providing tests.
LGTM.
chibby0ne commented Jul 20, 2019
@mangrisano Thanks for the approval. Unfortunately the CI is failing in MacOS. If you can, would you give me any pointers as to the cause of the issue? I truly don't understand it 😞 |
chibby0ne commented Aug 1, 2019
Hi @mangrisano, and any others. Just a friendly ping to mention that this is ready to be merged. |
chibby0ne commented Aug 7, 2019
21deb92 to 94f62fbCompare
benjaminp left a comment
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.
I don't understand these raise_error changes. Those don't seem related to changing the underlying library call.
Modules/posixmodule.c Outdated
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.
seems like the right buffer size is actually TTY_NAME_MAX
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.
Correct. This macro wasn't mentioned in the version of the man pages of my local dev machine (i.e: man ttyname) but after googling this constant, it is indeed mentioned in man limits.h which is imported by Python.h in the base code.
Good catch! Thanks for the recommendation!
Uh oh!
There was an error while loading. Please reload this page.
Modules/posixmodule.c Outdated
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.
Prefer sizeof(buffer)
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.
Done.
bedevere-bot commented Sep 11, 2019
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
chibby0ne commented Sep 14, 2019
Well according to the discussion in: https://bugs.python.org/issue36161, due to the fact that we are now returning the error code set by I have made the requested changes; please review again |
bedevere-bot commented Sep 14, 2019
Thanks for making the requested changes! @benjaminp: please review the changes made to this pull request. |
benjaminp commented Sep 24, 2019
While I agree it's technically a breaking change, I think not raising errors from a failed cryptographic function is severely buggy behavior. "Errors should never pass silently."
I think errors should always be propagated from |
chibby0ne commented Sep 28, 2019
Wise aphorism! I agree wholeheartedly.
Yeah it looks like this will be eventually deprecated and removed. I've decided to simply raise the error in accordingly, since it helps the user but also we are not over engineering future deprecated code. |
chibby0ne commented Sep 28, 2019
I have made the requested changes; please review again |
bedevere-bot commented Sep 28, 2019
Thanks for making the requested changes! @benjaminp: please review the changes made to this pull request. |
benjaminp left a comment
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.
okay, but now the tests are failng
bedevere-bot commented Sep 28, 2019
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Modules/posixmodule.c Outdated
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.
Huh, maybe it's better to use sysconf(_SC_TTY_NAME_MAX) for portability.
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.
I wasn't sure about this because I saw the values were quite different between the ones used in OpenBSD and the ones used in Linux, but I agree is the more portable solution
Lib/crypt.py Outdated
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.
Can you check that the errno of this error is EINVAL?
I think it would also be good to ensure that at least one method works.
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.
Good thinking! Done! Thanks a lot 👍
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.
"Use ttyname_r instead of ttyname and crypt_r instead of crypt for thread safety."
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.
I forgot to update this, because it was autogenerated from the first commit. Thanks a lot for your review 😉
benjaminp left a comment
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.
There are really two logical changes in this PR: checking the error of crypt and using ttyname_r. It would make sense to split them into separate PRs I think.
Modules/posixmodule.c Outdated
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.
Nit: no space between the cast and the function call.
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.
Done!
Modules/posixmodule.c Outdated
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 branch now leaks buffer.
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.
Good catch! Thanks ;)
Modules/posixmodule.c Outdated
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.
Fold these two lines into one:
PyObject *res = PyUnicode_DecodeFSDefault(buffer); 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.
Done!
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 is not correct, though, since you're not using crypt_r any more. :P
(I should have seen that last time I looked at the message.)
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.
In that case will only leave this PR for the ttyname_r, and then create another one for just the error checking of crypt, and will change the news message accordingly.
bedevere-bot commented Oct 5, 2019
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
* Use dynamically-allocated buffer for ttyname_r buffer * In case there is an error with the crypt/crypt_r then raise the error, instead of failing silently. * Check for EINVAL (invalid argument) in errno when adding not supported cryptographic methods, such as Blowfish in the case of glibc, but raise other errors. * Use _SC_TTY_MAX_LENGTH for TTY_NAME_MAX Signed-off-by: Antonio Gutierrez <[email protected]>
c21c775 to 5799801Comparechibby0ne commented Oct 5, 2019
I have made the requested changes; please review again |
bedevere-bot commented Oct 5, 2019
Thanks for making the requested changes! @benjaminp: please review the changes made to this pull request. |
chibby0ne commented Oct 5, 2019
@benjaminp What do you think I should name the other PR? AFAIK the PR branch should match the name of the issue. Should I name |
chibby0ne commented Oct 7, 2019
Hi @benjaminp, the error check for crypt/crypt_r was moved to: #16599 |
benjaminp commented Oct 9, 2019
Thank you for the PR. |
…onGH-14868) Signed-off-by: Antonio Gutierrez <[email protected]>
PR python#14868 replaced the ttyname() call with ttyname_r(), but the old check remained.
…ython#128503) (cherry picked from commit e08b282) PR python#14868 replaced the ttyname() call with ttyname_r(), but the old check remained.
…#128503) PR python#14868 replaced the ttyname() call with ttyname_r(), but the old check remained.

Signed-off-by: Antonio Gutierrez [email protected]
https://bugs.python.org/issue36161