Skip to content
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

socket.setblocking(x) treats multiples of 2**32 as False #79372

Closed
izbyshev mannequin opened this issue Nov 8, 2018 · 1 comment
Closed

socket.setblocking(x) treats multiples of 2**32 as False #79372

izbyshev mannequin opened this issue Nov 8, 2018 · 1 comment
Labels
3.7 (EOL) end of life 3.8 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@izbyshev
Copy link
Mannequin

izbyshev mannequin commented Nov 8, 2018

BPO 35191
Nosy @vstinner, @serhiy-storchaka, @izbyshev
PRs
  • [3.11] bpo-35191: Fix unexpected integer truncation in socket.setblocking() #10415
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2018-11-08.15:43:43.083>
    labels = ['extension-modules', '3.8', 'type-bug', '3.7']
    title = 'socket.setblocking(x) treats multiples of 2**32 as False'
    updated_at = <Date 2018-11-08.15:46:37.663>
    user = 'https://github.com/izbyshev'

    bugs.python.org fields:

    activity = <Date 2018-11-08.15:46:37.663>
    actor = 'izbyshev'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2018-11-08.15:43:43.083>
    creator = 'izbyshev'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35191
    keywords = ['patch']
    message_count = 1.0
    messages = ['329478']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'serhiy.storchaka', 'izbyshev']
    pr_nums = ['10415']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue35191'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7', 'Python 3.8']

    @izbyshev
    Copy link
    Mannequin Author

    izbyshev mannequin commented Nov 8, 2018

    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 (

    if (internal_setblocking(s, block) == -1) {
    ). 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.

    @izbyshev izbyshev mannequin added 3.7 (EOL) end of life 3.8 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Nov 8, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant