_socket: `socket.sethostname()` reports a failed buffer export as an OS error, raising `SystemError`

Aperta
#161,665 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
networking

Direzione di ricerca

Start by running the reproducer, which calls socket.sethostname() with a bytes subclass whose buffer raises KeyError, and note the SystemError it produces. The body links PR gh-161684, so check that PR before starting, since the work may already be under way. Done means the original exception propagates to the caller instead of being reported as a SystemError, and a test covers that case.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

extension-modules topic-socket type-bug
Bug report

Summary

socket.sethostname() accepts a bytes subclass, and if getting a buffer from that object fails, the error is not reported. Instead SystemError is returned to caller.

SystemError: <class 'OSError'> returned a result with an exception set

Reproducer

import os
import socket

class B(bytes):
    def __buffer__(self, flags):
        raise KeyError("boom")

try:
    os.stat("/nonexistent")
except OSError:
    pass

socket.sethostname(B(b"h"))
Traceback (most recent call last):
  File "min.py", line 23, in <module>
    socket.sethostname(B(b"h"))
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^
SystemError: <class 'OSError'> returned a result with an exception set
CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs
  • gh-161684
Lingua principale
Python
Stelle
78.2k
Fork
36.6k
Merge medio
19h 57m
PR unite (30g)
630

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.