Skip to content

Commit

Permalink
[3.9] bpo-44493: Add missing terminated NUL in sockaddr_un's length (G…
Browse files Browse the repository at this point in the history
…H-26866) (GH-32140) (GH-32156)

Add missing terminated NUL in sockaddr_un's length

- Linux: https://man7.org/linux/man-pages/man7/unix.7.html
- *BSD: SUN_LEN
(cherry picked from commit f6b3a07)

Co-authored-by: ty <zonyitoo@users.noreply.github.com>

Automerge-Triggered-By: GH:gpshead
(cherry picked from commit 5944807)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
  • Loading branch information
miss-islington authored Mar 28, 2022
1 parent 1e3132b commit dae09c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add missing terminated NUL in sockaddr_un's length

This was potentially observable when using non-abstract AF_UNIX datagram sockets to processes written in another programming language.
7 changes: 6 additions & 1 deletion Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
"AF_UNIX path too long");
goto unix_out;
}

*len_ret = path.len + offsetof(struct sockaddr_un, sun_path);
}
else
#endif /* linux */
Expand All @@ -1733,10 +1735,13 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
goto unix_out;
}
addr->sun_path[path.len] = 0;

/* including the tailing NUL */
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path) + 1;
}
addr->sun_family = s->sock_family;
memcpy(addr->sun_path, path.buf, path.len);
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path);

retval = 1;
unix_out:
PyBuffer_Release(&path);
Expand Down

0 comments on commit dae09c2

Please sign in to comment.