classification
Title: socket.setblocking(x) treats multiples of 2**32 as False
Type: behavior Stage: patch review
Components: Extension Modules Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: izbyshev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2018-11-08 15:43 by izbyshev, last changed 2018-11-08 15:46 by izbyshev.

Pull Requests
URL Status Linked Edit
PR 10415 open izbyshev, 2018-11-08 15:46
Messages (1)
msg329478 - (view) Author: Alexey Izbyshev (izbyshev) * Date: 2018-11-08 15:43
UBSAN with -fsanitize=implicit-integer-truncation reported a suspicious case:

testSetBlocking_overflow (test.test_socket.NonBlockingTCPTests) ... /scratch2/izbyshev/cpython/Modules/socketmodule.c:2688:33: runtime error: implicit conversion from type 'long' of value 4294967296 (64-bit, signed) to type 'int' changed the value to 0 (32-bit, signed)

It turned out that sock_setblocking() converts its (logically boolean) argument to long, but then passes it to internal_setblocking() which accepts int (https://github.com/python/cpython/blob/fd512d76456b65c529a5bc58d8cfe73e4a10de7a/Modules/socketmodule.c#L2688). This results in unexpected truncation on platforms with 64-bit long.

testSetBlocking_overflow() which is supposed to check this doesn't work because it only checks socket timeout which is updated correctly. However, the actual state of socket descriptor is changed to the opposite value (non-blocking) in this case.
History
Date User Action Args
2018-11-08 15:46:37izbyshevsetkeywords: + patch
stage: patch review
pull_requests: + pull_request9695
2018-11-08 15:43:43izbyshevcreate