public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2847] sanitizer: Cherry-pick realpath fix
@ 2021-08-11  8:26 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-08-11  8:26 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0e6017f5b4f13906dd2c09b25403ffa94a80181f

commit r12-2847-g0e6017f5b4f13906dd2c09b25403ffa94a80181f
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Aug 11 10:23:34 2021 +0200

    sanitizer: Cherry-pick realpath fix
    
    tsan in some cases starts ignoring interceptors and only calls the
    intercepted functions.  But for realpath the behavior for NULL second argument
    was only handled in the interceptor and intercepted function was the one
    found by dlsym which is often one that doesn't handle NULL as second argument.
    
    Fixed by using dlvsym with "GLIBC_2.3" if possible for intercepted function
    and don't emulate behavior in the wrapper.
    
    2021-08-11  Jakub Jelinek  <jakub@redhat.com>
    
            * sanitizer_common/sanitizer_common_interceptors.inc: Cherry-pick
            llvm-project revision faef0d042f523357fe5590e7cb6a8391cf0351a8.

Diff:
---
 .../sanitizer_common/sanitizer_common_interceptors.inc       | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
index 6205d853a4c..5ac6cf45fd2 100644
--- a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
@@ -3664,21 +3664,11 @@ INTERCEPTOR(char *, realpath, const char *path, char *resolved_path) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, realpath, path, resolved_path);
   if (path) COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
-
-  // Workaround a bug in glibc where dlsym(RTLD_NEXT, ...) returns the oldest
-  // version of a versioned symbol. For realpath(), this gives us something
-  // (called __old_realpath) that does not handle NULL in the second argument.
-  // Handle it as part of the interceptor.
-  char *allocated_path = nullptr;
-  if (!resolved_path)
-    allocated_path = resolved_path = (char *)WRAP(malloc)(path_max + 1);
-
   char *res = REAL(realpath)(path, resolved_path);
-  if (allocated_path && !res) WRAP(free)(allocated_path);
   if (res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, res, REAL(strlen)(res) + 1);
   return res;
 }
-#define INIT_REALPATH COMMON_INTERCEPT_FUNCTION(realpath);
+#define INIT_REALPATH COMMON_INTERCEPT_FUNCTION_GLIBC_VER_MIN(realpath, "GLIBC_2.3");
 #else
 #define INIT_REALPATH
 #endif


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-11  8:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11  8:26 [gcc r12-2847] sanitizer: Cherry-pick realpath fix Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).