Mercurial > cpython-lru_cache-weakref
diff Modules/socketmodule.c @ 73998:1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
encoding and the surrogateescape error handler, rather than UTF-8. Patch
by David Watson.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Fri, 16 Dec 2011 14:46:36 +0100 |
| parents | d48b4a1c511a |
| children | 51412b4b81ae |
line wrap: on
line diff
--- a/Modules/socketmodule.c Fri Dec 16 12:29:37 2011 +0100 +++ b/Modules/socketmodule.c Fri Dec 16 14:46:36 2011 +0100 @@ -1073,7 +1073,7 @@ #endif /* linux */ { /* regular NULL-terminated string */ - return PyUnicode_FromString(a->sun_path); + return PyUnicode_DecodeFSDefault(a->sun_path); } } #endif /* AF_UNIX */ @@ -1269,8 +1269,18 @@ struct sockaddr_un* addr; char *path; int len; - if (!PyArg_Parse(args, "s#", &path, &len)) - return 0; + int retval = 0; + + /* PEP 383. Not using PyUnicode_FSConverter since we need to + allow embedded nulls on Linux. */ + if (PyUnicode_Check(args)) { + if ((args = PyUnicode_EncodeFSDefault(args)) == NULL) + return 0; + } + else + Py_INCREF(args); + if (!PyArg_Parse(args, "y#", &path, &len)) + goto unix_out; addr = (struct sockaddr_un*)addr_ret; #ifdef linux @@ -1279,7 +1289,7 @@ if (len > sizeof addr->sun_path) { PyErr_SetString(PyExc_OSError, "AF_UNIX path too long"); - return 0; + goto unix_out; } } else @@ -1289,7 +1299,7 @@ if (len >= sizeof addr->sun_path) { PyErr_SetString(PyExc_OSError, "AF_UNIX path too long"); - return 0; + goto unix_out; } addr->sun_path[len] = 0; } @@ -1300,7 +1310,10 @@ #else *len_ret = len + offsetof(struct sockaddr_un, sun_path); #endif - return 1; + retval = 1; + unix_out: + Py_DECREF(args); + return retval; } #endif /* AF_UNIX */
