Allow AF_UNIX pathnames up to the maximum 108 bytes on Linux, since it does not require sun_path to be null terminated. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1187,27 +1187,16 @@ getsockaddrarg(PySocketSockObject *s, Py addr = (struct sockaddr_un*)addr_ret; #ifdef linux - if (len > 0 && path[0] == 0) { - /* Linux abstract namespace extension */ - if (len > sizeof addr->sun_path) { - PyErr_SetString(socket_error, - "AF_UNIX path too long"); - return 0; - } - } - else -#endif /* linux */ - { - /* regular NULL-terminated string */ - if (len >= sizeof addr->sun_path) { - PyErr_SetString(socket_error, - "AF_UNIX path too long"); - return 0; - } - addr->sun_path[len] = 0; + if (len > sizeof(addr->sun_path)) { +#else + if (len >= sizeof(addr->sun_path)) { +#endif + PyErr_SetString(socket_error, "AF_UNIX path too long"); + return 0; } addr->sun_family = s->sock_family; memcpy(addr->sun_path, path, len); + memset(addr->sun_path + len, 0, sizeof(addr->sun_path) - len); #if defined(PYOS_OS2) *len_ret = sizeof(*addr); #else