summaryrefslogtreecommitdiffstats
path: root/Modules/grpmodule.c
diff options
context:
space:
mode:
authorChristopher Chavez <chrischavez@gmx.us>2023-07-27 19:20:25 (GMT)
committerGitHub <noreply@github.com>2023-07-27 19:20:25 (GMT)
commitf01e4cedba1a17d321664834bb255d9d04ad16ce (patch)
tree6fe5741dbb1406037f5d14e55b613bed4d40e291 /Modules/grpmodule.c
parent983305268e2291b0a7835621b81bf40cba7c27f3 (diff)
downloadcpython-f01e4cedba1a17d321664834bb255d9d04ad16ce.zip
cpython-f01e4cedba1a17d321664834bb255d9d04ad16ce.tar.gz
cpython-f01e4cedba1a17d321664834bb255d9d04ad16ce.tar.bz2
gh-104432: Use `memcpy()` to avoid misaligned loads (#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.
Diffstat (limited to 'Modules/grpmodule.c')
-rw-r--r--Modules/grpmodule.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c
index 57cdde6..f570929 100644
--- a/Modules/grpmodule.c
+++ b/Modules/grpmodule.c
@@ -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);