diff --git a/include/my_valgrind.h b/include/my_valgrind.h index 260521d4d4b..a24ad597d36 100644 --- a/include/my_valgrind.h +++ b/include/my_valgrind.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010, 2020, MariaDB Corporation. +/* Copyright (C) 2010, 2022, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,6 +37,11 @@ # define MEM_GET_VBITS(a,b,len) __msan_copy_shadow(b,a,len) # define MEM_SET_VBITS(a,b,len) __msan_copy_shadow(a,b,len) # define REDZONE_SIZE 8 +# ifdef __linux__ +# define MSAN_STAT_WORKAROUND(st) MEM_MAKE_DEFINED(st, sizeof(*st)) +# else +# define MSAN_STAT_WORKAROUND(st) ((void) 0) +# endif #elif defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind) # include # define HAVE_MEM_CHECK @@ -49,6 +54,7 @@ # define MEM_GET_VBITS(a,b,len) VALGRIND_GET_VBITS(a,b,len) # define MEM_SET_VBITS(a,b,len) VALGRIND_SET_VBITS(a,b,len) # define REDZONE_SIZE 8 +# define MSAN_STAT_WORKAROUND(st) ((void) 0) #elif defined(__SANITIZE_ADDRESS__) && (!defined(_MSC_VER) || defined (__clang__)) # include /* How to do manual poisoning: @@ -62,6 +68,7 @@ https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */ # define MEM_CHECK_DEFINED(a,len) ((void) 0) # define MEM_GET_VBITS(a,b,len) ((void) 0) # define MEM_SET_VBITS(a,b,len) ((void) 0) +# define MSAN_STAT_WORKAROUND(st) ((void) 0) # define REDZONE_SIZE 8 #else # define MEM_UNDEFINED(a,len) ((void) 0) @@ -73,6 +80,7 @@ https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */ # define MEM_GET_VBITS(a,b,len) ((void) 0) # define MEM_SET_VBITS(a,b,len) ((void) 0) # define REDZONE_SIZE 0 +# define MSAN_STAT_WORKAROUND(st) ((void) 0) #endif /* __has_feature(memory_sanitizer) */ #ifdef HAVE_valgrind diff --git a/mysys/my_lib.c b/mysys/my_lib.c index ca50699b4c3..fedd1c7ab4d 100644 --- a/mysys/my_lib.c +++ b/mysys/my_lib.c @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. - Copyright (c) 2008, 2020, MariaDB Corporation. + Copyright (c) 2008, 2022, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -350,11 +350,14 @@ MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags) my_flags))) goto error; #ifndef _WIN32 - if (! stat((char *) path, (struct stat *) stat_area) ) - DBUG_RETURN(stat_area); + if (!stat((char *) path, (struct stat *) stat_area)) + { + MSAN_STAT_WORKAROUND(stat_area); + DBUG_RETURN(stat_area); + } #else - if (! my_win_stat(path, stat_area) ) - DBUG_RETURN(stat_area); + if (!my_win_stat(path, stat_area)) + DBUG_RETURN(stat_area); #endif DBUG_PRINT("error",("Got errno: %d from stat", errno)); my_errno= errno; diff --git a/mysys/my_symlink.c b/mysys/my_symlink.c index 323ae69a39c..8238e501e7f 100644 --- a/mysys/my_symlink.c +++ b/mysys/my_symlink.c @@ -1,6 +1,6 @@ /* Copyright (c) 2001, 2011, Oracle and/or its affiliates - Copyright (c) 2010, 2017, MariaDB + Copyright (c) 2010, 2022, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -113,7 +113,10 @@ int my_is_symlink(const char *filename __attribute__((unused))) { #if defined (HAVE_LSTAT) && defined (S_ISLNK) struct stat stat_buff; - return !lstat(filename, &stat_buff) && S_ISLNK(stat_buff.st_mode); + if (lstat(filename, &stat_buff)) + return 0; + MSAN_STAT_WORKAROUND(&stat_buff); + return !!S_ISLNK(stat_buff.st_mode); #elif defined (_WIN32) DWORD dwAttr = GetFileAttributes(filename); return (dwAttr != INVALID_FILE_ATTRIBUTES) && diff --git a/sql/datadict.cc b/sql/datadict.cc index e09eee98565..37f90d0309a 100644 --- a/sql/datadict.cc +++ b/sql/datadict.cc @@ -128,6 +128,8 @@ Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name) if (mysql_file_fstat(file, &state, MYF(MY_WME))) goto err; + MSAN_STAT_WORKAROUND(&state); + if (mysql_file_seek(file, 0, SEEK_SET, MYF(MY_WME))) goto err; diff --git a/sql/discover.cc b/sql/discover.cc index 4267f97cf59..22d7008630a 100644 --- a/sql/discover.cc +++ b/sql/discover.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. - Copyright (c) 2009, 2020, MariaDB Corporation. + Copyright (c) 2009, 2022, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -72,6 +72,7 @@ int readfrm(const char *name, const uchar **frmdata, size_t *len) error= 2; if (mysql_file_fstat(file, &state, MYF(0))) goto err; + MSAN_STAT_WORKAROUND(&state); read_len= (size_t)MY_MIN(FRM_MAX_SIZE, state.st_size); // safety // Read whole frm file diff --git a/sql/parse_file.cc b/sql/parse_file.cc index 59b4027a352..78093316d88 100644 --- a/sql/parse_file.cc +++ b/sql/parse_file.cc @@ -415,6 +415,8 @@ sql_parse_prepare(const LEX_CSTRING *file_name, MEM_ROOT *mem_root, DBUG_RETURN(0); } + MSAN_STAT_WORKAROUND(&stat_info); + if (stat_info.st_size > INT_MAX-1) { my_error(ER_FPARSER_TOO_BIG_FILE, MYF(0), file_name->str); diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index eb9b4e00bd2..fb240943298 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -953,7 +953,7 @@ os_file_status_posix( if (!ret) { /* file exists, everything OK */ - + MSAN_STAT_WORKAROUND(&statinfo); } else if (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG) { /* file does not exist */ return(true); @@ -1548,8 +1548,10 @@ bool os_file_close_func(os_file_t file) os_offset_t os_file_get_size(os_file_t file) { - struct stat statbuf; - return fstat(file, &statbuf) ? os_offset_t(-1) : statbuf.st_size; + struct stat statbuf; + if (fstat(file, &statbuf)) return os_offset_t(-1); + MSAN_STAT_WORKAROUND(&statbuf); + return statbuf.st_size; } /** Gets a file size. @@ -1566,6 +1568,7 @@ os_file_get_size( int ret = stat(filename, &s); if (ret == 0) { + MSAN_STAT_WORKAROUND(&s); file_size.m_total_size = s.st_size; /* st_blocks is in 512 byte sized blocks */ file_size.m_alloc_size = s.st_blocks * 512; @@ -1610,6 +1613,8 @@ os_file_get_status_posix( return(DB_FAIL); } + MSAN_STAT_WORKAROUND(statinfo); + switch (statinfo->st_mode & S_IFMT) { case S_IFDIR: stat_info->type = OS_FILE_TYPE_DIR; @@ -3300,6 +3305,7 @@ fallback: if (fstat(file, &statbuf)) { err = errno; } else { + MSAN_STAT_WORKAROUND(&statbuf); os_offset_t current_size = statbuf.st_size; if (current_size >= size) { return true; @@ -4186,6 +4192,7 @@ void fil_node_t::find_metadata(os_file_t file #else struct stat sbuf; if (!statbuf && !fstat(file, &sbuf)) { + MSAN_STAT_WORKAROUND(&sbuf); statbuf = &sbuf; } if (statbuf) { @@ -4229,6 +4236,7 @@ bool fil_node_t::read_page0() if (fstat(handle, &statbuf)) { return false; } + MSAN_STAT_WORKAROUND(&statbuf); os_offset_t size_bytes = statbuf.st_size; #else os_offset_t size_bytes = os_file_get_size(handle); diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c index a2e3f9b738d..8b4dc5da561 100644 --- a/strings/my_vsnprintf.c +++ b/strings/my_vsnprintf.c @@ -704,10 +704,11 @@ size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n, } else if (*fmt == 'f' || *fmt == 'g') { + double d; #if __has_feature(memory_sanitizer) /* QQ: MSAN has double trouble? */ __msan_check_mem_is_initialized(ap, sizeof(double)); #endif - double d= va_arg(ap, double); + d= va_arg(ap, double); #if __has_feature(memory_sanitizer) /* QQ: MSAN has double trouble? */ __msan_unpoison(&d, sizeof(double)); #endif