]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38730: Replace strncpy in import.c with memcpy. (GH-17633)
authorBenjamin Peterson <benjamin@python.org>
Tue, 17 Dec 2019 00:39:57 +0000 (16:39 -0800)
committerGitHub <noreply@github.com>
Tue, 17 Dec 2019 00:39:57 +0000 (16:39 -0800)
In all these cases, we know the exact length we want copied, so memcpy is the right function to use.

Python/import.c

index ccbd949e624f149fbb5aadbf568b5727ef0e4fad..b79354b37a406450d475cd6566dae0644d68af2f 100644 (file)
@@ -2456,7 +2456,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
                                 "Module name too long");
                 return NULL;
             }
-            strncpy(buf, start, len);
+            memcpy(buf, start, len);
             buf[len] = '\0';
             pkgname = PyString_FromString(buf);
             if (pkgname == NULL) {
@@ -2554,7 +2554,7 @@ load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf,
                         "Module name too long");
         return NULL;
     }
-    strncpy(p, name, len);
+    memcpy(p, name, len);
     p[len] = '\0';
     *p_buflen = p+len-buf;
 
@@ -2568,7 +2568,7 @@ load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf,
                 Py_DECREF(result);
                 return NULL;
             }
-            strncpy(buf, name, len);
+            memcpy(buf, name, len);
             buf[len] = '\0';
             *p_buflen = len;
         }