summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-12-16 13:46:36 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-12-16 13:46:36 (GMT)
commit6ec29e299b663662a1610a740c4c7f8066fc63a6 (patch)
tree7bf65e75b7d28f95f679bd164e7db38173585a9e /Modules/socketmodule.c
parentab0e9f7089c04df546af6cacbc8751247cf4020a (diff)
downloadcpython-6ec29e299b663662a1610a740c4c7f8066fc63a6.zip
cpython-6ec29e299b663662a1610a740c4c7f8066fc63a6.tar.gz
cpython-6ec29e299b663662a1610a740c4c7f8066fc63a6.tar.bz2
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.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 40a18ed..c828d49 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1073,7 +1073,7 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
#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 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
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 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
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 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
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 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
#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 */