Skip to content

bpo-46887: Work around clang MSAN bug on stat()/fstat() #31633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2484,6 +2484,12 @@ posix_do_stat(PyObject *module, const char *function_name, path_t *path,
STRUCT_STAT st;
int result;

# if __has_feature(memory_sanitizer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires a check if __has_feature is defined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyport.h defines _Py_MEMORY_SANITIZER for us, taking care of all of the compiler/platform conditionals around this.

// bpo-46887: Work around clang MSAN bug:
// https://github.com/llvm/llvm-project/issues/54131
memset(&st, 0, sizeof(st));
# endif

#ifdef HAVE_FSTATAT
int fstatat_unavailable = 0;
#endif
Expand Down
14 changes: 13 additions & 1 deletion Python/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,13 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
status->st_ino = (((uint64_t)info.nFileIndexHigh) << 32) + info.nFileIndexLow;
return 0;
#else

# if __has_feature(memory_sanitizer)
// bpo-46887: Work around clang MSAN bug:
// https://github.com/llvm/llvm-project/issues/54131
memset(status, 0, sizeof(*status));
# endif

return fstat(fd, status);
#endif
}
Expand Down Expand Up @@ -1225,6 +1232,11 @@ _Py_wstat(const wchar_t* path, struct stat *buf)
errno = EINVAL;
return -1;
}
# if __has_feature(memory_sanitizer)
// bpo-46887: Work around clang MSAN bug:
// https://github.com/llvm/llvm-project/issues/54131
memset(buf, 0, sizeof(*buf));
# endif
err = stat(fname, buf);
PyMem_RawFree(fname);
#endif
Expand Down Expand Up @@ -2093,7 +2105,7 @@ join_relfile(wchar_t *buffer, size_t bufsize,
const wchar_t *dirname, const wchar_t *relfile)
{
#ifdef MS_WINDOWS
if (FAILED(PathCchCombineEx(buffer, bufsize, dirname, relfile,
if (FAILED(PathCchCombineEx(buffer, bufsize, dirname, relfile,
PATHCCH_ALLOW_LONG_PATHS))) {
return -1;
}
Expand Down