Skip to content

Commit 5cbf171

Browse files
gpsheadcsabella
authored andcommitted
bpo-35214: Annotate posix calls for clang MSan. (python#11389)
It doesn't know the details of a few less common libc functions.
1 parent fe9ade5 commit 5cbf171

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
clang Memory Sanitizer build instrumentation was added to work around false
2-
positives from socket, time, test_io, and test_faulthandler.
2+
positives from posix, socket, time, test_io, and test_faulthandler.

Modules/posixmodule.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ static int win32_can_symlink = 0;
367367
#define HAVE_STRUCT_STAT_ST_FSTYPE 1
368368
#endif
369369

370+
#ifdef _Py_MEMORY_SANITIZER
371+
# include <sanitizer/msan_interface.h>
372+
#endif
373+
370374
#ifdef HAVE_FORK
371375
static void
372376
run_at_forkers(PyObject *lst, int reverse)
@@ -5493,6 +5497,9 @@ os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
54935497
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path->object);
54945498
goto exit;
54955499
}
5500+
#ifdef _Py_MEMORY_SANITIZER
5501+
__msan_unpoison(&pid, sizeof(pid));
5502+
#endif
54965503
result = PyLong_FromPid(pid);
54975504

54985505
exit:
@@ -6098,6 +6105,9 @@ os_sched_rr_get_interval_impl(PyObject *module, pid_t pid)
60986105
posix_error();
60996106
return -1.0;
61006107
}
6108+
#ifdef _Py_MEMORY_SANITIZER
6109+
__msan_unpoison(&interval, sizeof(interval));
6110+
#endif
61016111
return (double)interval.tv_sec + 1e-9*interval.tv_nsec;
61026112
}
61036113
#endif /* HAVE_SCHED_RR_GET_INTERVAL */
@@ -6568,6 +6578,12 @@ posix_getgrouplist(PyObject *self, PyObject *args)
65686578
return posix_error();
65696579
}
65706580

6581+
#ifdef _Py_MEMORY_SANITIZER
6582+
/* Clang memory sanitizer libc intercepts don't know getgrouplist. */
6583+
__msan_unpoison(&ngroups, sizeof(ngroups));
6584+
__msan_unpoison(groups, ngroups*sizeof(*groups));
6585+
#endif
6586+
65716587
list = PyList_New(ngroups);
65726588
if (list == NULL) {
65736589
PyMem_Del(groups);

0 commit comments

Comments
 (0)