mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-132075: Fix possible use of sockaddr structures with uninitialized members (GH-132076)
Now all structure members are initialized with zeroes by default.
This commit is contained in:
parent
255eb375a7
commit
345baa77ba
2 changed files with 15 additions and 0 deletions
|
@ -1820,6 +1820,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
assert(path.len >= 0);
|
||||
|
||||
struct sockaddr_un* addr = &addrbuf->un;
|
||||
memset(addr, 0, sizeof(struct sockaddr_un));
|
||||
#ifdef __linux__
|
||||
if (path.len == 0 || *(const char *)path.buf == 0) {
|
||||
/* Linux abstract namespace extension:
|
||||
|
@ -1863,6 +1864,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
{
|
||||
int pid, groups;
|
||||
struct sockaddr_nl* addr = &addrbuf->nl;
|
||||
memset(addr, 0, sizeof(struct sockaddr_nl));
|
||||
if (!PyTuple_Check(args)) {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError,
|
||||
|
@ -1890,6 +1892,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
{
|
||||
unsigned int node, port;
|
||||
struct sockaddr_qrtr* addr = &addrbuf->sq;
|
||||
memset(addr, 0, sizeof(struct sockaddr_qrtr));
|
||||
if (!PyTuple_Check(args)) {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError,
|
||||
|
@ -1969,6 +1972,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
return 0;
|
||||
}
|
||||
struct sockaddr_in* addr = &addrbuf->in;
|
||||
memset(addr, 0, sizeof(struct sockaddr_in));
|
||||
result = setipaddr(s->state, host.buf, (struct sockaddr *)addr,
|
||||
sizeof(*addr), AF_INET);
|
||||
idna_cleanup(&host);
|
||||
|
@ -2014,6 +2018,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
return 0;
|
||||
}
|
||||
struct sockaddr_in6* addr = &addrbuf->in6;
|
||||
memset(addr, 0, sizeof(struct sockaddr_in6));
|
||||
result = setipaddr(s->state, host.buf, (struct sockaddr *)addr,
|
||||
sizeof(*addr), AF_INET6);
|
||||
idna_cleanup(&host);
|
||||
|
@ -2078,6 +2083,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
{
|
||||
const char *straddr;
|
||||
struct sockaddr_rc *addr = &addrbuf->bt_rc;
|
||||
memset(addr, 0, sizeof(struct sockaddr_rc));
|
||||
_BT_RC_MEMB(addr, family) = AF_BLUETOOTH;
|
||||
#ifdef MS_WINDOWS
|
||||
unsigned long channel;
|
||||
|
@ -2104,6 +2110,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
case BTPROTO_HCI:
|
||||
{
|
||||
struct sockaddr_hci *addr = &addrbuf->bt_hci;
|
||||
memset(addr, 0, sizeof(struct sockaddr_hci));
|
||||
#if defined(__NetBSD__) || defined(__DragonFly__)
|
||||
const char *straddr;
|
||||
_BT_HCI_MEMB(addr, family) = AF_BLUETOOTH;
|
||||
|
@ -2155,6 +2162,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
const char *straddr;
|
||||
|
||||
struct sockaddr_sco *addr = &addrbuf->bt_sco;
|
||||
memset(addr, 0, sizeof(struct sockaddr_sco));
|
||||
_BT_SCO_MEMB(addr, family) = AF_BLUETOOTH;
|
||||
if (!PyBytes_Check(args)) {
|
||||
PyErr_Format(PyExc_OSError,
|
||||
|
@ -2232,6 +2240,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
return 0;
|
||||
}
|
||||
struct sockaddr_ll* addr = &addrbuf->ll;
|
||||
memset(addr, 0, sizeof(struct sockaddr_ll));
|
||||
addr->sll_family = AF_PACKET;
|
||||
addr->sll_protocol = htons((short)protoNumber);
|
||||
addr->sll_ifindex = ifr.ifr_ifindex;
|
||||
|
@ -2318,6 +2327,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
struct ifreq ifr;
|
||||
Py_ssize_t len;
|
||||
struct sockaddr_can *addr = &addrbuf->can;
|
||||
memset(addr, 0, sizeof(struct sockaddr_can));
|
||||
|
||||
if (!PyTuple_Check(args)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
@ -2370,6 +2380,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
unsigned long int rx_id, tx_id;
|
||||
|
||||
struct sockaddr_can *addr = &addrbuf->can;
|
||||
memset(addr, 0, sizeof(struct sockaddr_can));
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O&kk", PyUnicode_FSConverter,
|
||||
&interfaceName,
|
||||
|
@ -2417,6 +2428,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
uint8_t j1939_addr;
|
||||
|
||||
struct sockaddr_can *addr = &addrbuf->can;
|
||||
memset(addr, 0, sizeof(struct sockaddr_can));
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O&KIB", PyUnicode_FSConverter,
|
||||
&interfaceName,
|
||||
|
@ -2469,6 +2481,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
|||
case SYSPROTO_CONTROL:
|
||||
{
|
||||
struct sockaddr_ctl *addr = &addrbuf->ctl;
|
||||
memset(addr, 0, sizeof(struct sockaddr_ctl));
|
||||
addr->sc_family = AF_SYSTEM;
|
||||
addr->ss_sysaddr = AF_SYS_CONTROL;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue