summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2018-12-10 10:22:37 (GMT)
committerVictor Stinner <vstinner@redhat.com>2018-12-10 10:22:37 (GMT)
commit2eb6ad8578fa9d764c21a92acd8e054e3202ad19 (patch)
treeec8156905638640f904aa7f692e2cbdbe861e38b /Modules
parent8e0418688906206fe59bd26344320c0fc026849e (diff)
downloadcpython-2eb6ad8578fa9d764c21a92acd8e054e3202ad19.zip
cpython-2eb6ad8578fa9d764c21a92acd8e054e3202ad19.tar.gz
cpython-2eb6ad8578fa9d764c21a92acd8e054e3202ad19.tar.bz2
bpo-35050: AF_ALG length check off-by-one error (GH-10058)
The length check for AF_ALG salg_name and salg_type had a off-by-one error. The code assumed that both values are not necessarily NULL terminated. However the Kernel code for alg_bind() ensures that the last byte of both strings are NULL terminated. Signed-off-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 04bfdaf..40f1ca6 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2245,13 +2245,15 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
{
return 0;
}
- /* sockaddr_alg has fixed-sized char arrays for type and name */
- if (strlen(type) > sizeof(sa->salg_type)) {
+ /* sockaddr_alg has fixed-sized char arrays for type, and name
+ * both must be NULL terminated.
+ */
+ if (strlen(type) >= sizeof(sa->salg_type)) {
PyErr_SetString(PyExc_ValueError, "AF_ALG type too long.");
return 0;
}
strncpy((char *)sa->salg_type, type, sizeof(sa->salg_type));
- if (strlen(name) > sizeof(sa->salg_name)) {
+ if (strlen(name) >= sizeof(sa->salg_name)) {
PyErr_SetString(PyExc_ValueError, "AF_ALG name too long.");
return 0;
}