Skip to content

Commit 052f47e

Browse files
authored
bpo-38730: Replace strncpy in import.c with memcpy. (GH-17633)
In all these cases, we know the exact length we want copied, so memcpy is the right function to use.
1 parent de44813 commit 052f47e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Python/import.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
24562456
"Module name too long");
24572457
returnNULL;
24582458
}
2459-
strncpy(buf, start, len);
2459+
memcpy(buf, start, len);
24602460
buf[len] ='\0';
24612461
pkgname=PyString_FromString(buf);
24622462
if (pkgname==NULL) {
@@ -2554,7 +2554,7 @@ load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf,
25542554
"Module name too long");
25552555
returnNULL;
25562556
}
2557-
strncpy(p, name, len);
2557+
memcpy(p, name, len);
25582558
p[len] ='\0';
25592559
*p_buflen=p+len-buf;
25602560

@@ -2568,7 +2568,7 @@ load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf,
25682568
Py_DECREF(result);
25692569
returnNULL;
25702570
}
2571-
strncpy(buf, name, len);
2571+
memcpy(buf, name, len);
25722572
buf[len] ='\0';
25732573
*p_buflen=len;
25742574
}

0 commit comments

Comments
 (0)
close