This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: crypt.crypt fail with OSError "[Errno 22] Invalid argument" on 3.9 where it didn't on 3.8
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: corona10, vinay.sajip, vstinner
Priority: normal Keywords: 3.9regression

Created on 2020-01-10 16:21 by vinay.sajip, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg359732 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-01-10 16:21
The following script (cryptest.py):

import crypt

for salt in ('foo', '$2a$04$5BJqKfqMQvV7nS.yUguNcueVirQqDBGaLXSqj.rs.pZPlNR0UX/HK'):
    t = 'test'
    h = crypt.crypt(t, salt)
    print("'%s' with '%s' -> %s" % (t, salt, h))

crashes in 3.9, whereas it doesn't in earlier versions:

$ python2.7 cryptest.py 
'test' with 'foo' -> foy6TgL.HboTE
'test' with '$2a$04$5BJqKfqMQvV7nS.yUguNcueVirQqDBGaLXSqj.rs.pZPlNR0UX/HK' -> None
$ python3.7 cryptest.py 
'test' with 'foo' -> foy6TgL.HboTE
'test' with '$2a$04$5BJqKfqMQvV7nS.yUguNcueVirQqDBGaLXSqj.rs.pZPlNR0UX/HK' -> None
$ python3.8 cryptest.py 
'test' with 'foo' -> foy6TgL.HboTE
'test' with '$2a$04$5BJqKfqMQvV7nS.yUguNcueVirQqDBGaLXSqj.rs.pZPlNR0UX/HK' -> None
$ python3.9 cryptest.py 
'test' with 'foo' -> foy6TgL.HboTE
Traceback (most recent call last):
  File "/home/vinay/projects/scratch/cpython/cryptest.py", line 5, in <module>
    h = crypt.crypt(t, salt)
  File "/home/vinay/.local/lib/python3.9/crypt.py", line 82, in crypt
    return _crypt.crypt(word, salt)
OSError: [Errno 22] Invalid argument

This is on Ubuntu 18.04, 64-bit.
msg359733 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-01-10 16:26
I fail to reproduce the issue on the master branch of Python on Fedora 31.
msg359734 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-01-10 16:29
I also fail to reproduce the issue on the master branch of Python on macOS.
msg359751 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-01-10 19:45
I can also reproduce it on Ubuntu 16.04.6 LTS (the first Ubuntu was the Linux Mint version based on Ubuntu 18.04).
msg359752 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-01-10 19:58
Another data point: both failing machines were VMware virtual machines.
msg359761 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-01-10 21:48
It appears that a check for the return value from the crypt/crypt_r primitives was added to fix bpo-38402. So, this is expected behaviour in Python 3.9. Change was in

https://github.com/python/cpython/commit/0d3fe8ae4961bf551e7d5e42559e2ede1a08fd7c
History
Date User Action Args
2022-04-11 14:59:25adminsetgithub: 83470
2020-01-10 21:48:58vinay.sajipsetstatus: open -> closed
resolution: not a bug
messages: + msg359761

stage: resolved
2020-01-10 19:58:19vinay.sajipsetmessages: + msg359752
2020-01-10 19:45:04vinay.sajipsetmessages: + msg359751
2020-01-10 16:29:08corona10setnosy: + corona10
messages: + msg359734
2020-01-10 16:27:03vstinnersettitle: crypt.crypt crashes on 3.9 where it didn't on 3.8 -> crypt.crypt fail with OSError "[Errno 22] Invalid argument" on 3.9 where it didn't on 3.8
2020-01-10 16:26:39vstinnersetnosy: + vstinner
messages: + msg359733
2020-01-10 16:21:48vinay.sajipcreate