mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
[3.12] gh-104432: Use memcpy() to avoid misaligned loads (GH-104433) (#107355)
gh-104432: Use `memcpy()` to avoid misaligned loads (GH-104433)
Fix potential unaligned memory access on C APIs involving returned sequences
of `char *` pointers within the :mod:`grp` and :mod:`socket` modules. These
were revealed using a ``-fsaniziter=alignment`` build on ARM macOS.
(cherry picked from commit f01e4cedba)
Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
This commit is contained in:
parent
c580527d92
commit
5daf19d763
3 changed files with 29 additions and 7 deletions
|
|
@ -65,8 +65,14 @@ mkgrent(PyObject *module, struct group *p)
|
|||
Py_DECREF(v);
|
||||
return NULL;
|
||||
}
|
||||
for (member = p->gr_mem; *member != NULL; member++) {
|
||||
PyObject *x = PyUnicode_DecodeFSDefault(*member);
|
||||
for (member = p->gr_mem; ; member++) {
|
||||
char *group_member;
|
||||
// member can be misaligned
|
||||
memcpy(&group_member, member, sizeof(group_member));
|
||||
if (group_member == NULL) {
|
||||
break;
|
||||
}
|
||||
PyObject *x = PyUnicode_DecodeFSDefault(group_member);
|
||||
if (x == NULL || PyList_Append(w, x) != 0) {
|
||||
Py_XDECREF(x);
|
||||
Py_DECREF(w);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue