Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1c478f

Browse files
committed
The tp_new implementation should initialize the errorhandler field,
otherwise this code could segfault: from socket import socket s = socket.__new__(socket) s.recv(100)
1 parent a312c3a commit e1c478f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Modules/socketmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,8 +1690,10 @@ PySocketSock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
16901690
PyObject *new;
16911691

16921692
new = type->tp_alloc(type, 0);
1693-
if (new != NULL)
1693+
if (new != NULL) {
16941694
((PySocketSockObject *)new)->sock_fd = -1;
1695+
((PySocketSockObject *)new)->errorhandler = &PySocket_Err;
1696+
}
16951697
return new;
16961698
}
16971699

0 commit comments

Comments
 (0)