]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44493: Add missing terminated NUL in sockaddr_un's length (GH-26866)
authorty <zonyitoo@users.noreply.github.com>
Sun, 27 Mar 2022 20:22:22 +0000 (04:22 +0800)
committerGitHub <noreply@github.com>
Sun, 27 Mar 2022 20:22:22 +0000 (13:22 -0700)
Add missing terminated NUL in sockaddr_un's length

- Linux: https://man7.org/linux/man-pages/man7/unix.7.html
- *BSD: SUN_LEN

Misc/NEWS.d/next/Library/2021-07-26-10-46-49.bpo-44493.xp3CRH.rst [new file with mode: 0644]
Modules/socketmodule.c

diff --git a/Misc/NEWS.d/next/Library/2021-07-26-10-46-49.bpo-44493.xp3CRH.rst b/Misc/NEWS.d/next/Library/2021-07-26-10-46-49.bpo-44493.xp3CRH.rst
new file mode 100644 (file)
index 0000000..390a722
--- /dev/null
@@ -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.
index 7f7af1895bd9f2d13f0a50ba51a993cc38b45a39..c7bc10b5dbbbcda8c4b60b971a6d6ba395639502 100644 (file)
@@ -1689,6 +1689,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 */
@@ -1700,10 +1702,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);