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

Abierto
#161,665 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
networking

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Python
Estrellas
78.2k
Forks
36.6k
Merge medio
19 h 57 min
PR fusionados (30 d)
630

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python/cpython

Todos los issues de python/cpython

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.